-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReferenceCountedObject.cs
33 lines (30 loc) · 1 KB
/
ReferenceCountedObject.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System.Runtime.InteropServices;
namespace ASCOM.LocalServer
{
/// <summary>
/// Class to keep track of COM object instanciations and destructions
/// </summary>
[ComVisible(false)]
public class ReferenceCountedObjectBase
{
/// <summary>
/// Called every time a driver instance is created
/// </summary>
public ReferenceCountedObjectBase()
{
// We increment the global count of objects.
Server.IncrementObjectCount();
}
/// <summary>
/// Called automatically by the garbage collection mechanic every time a driver instance is finalised (destroyed).
/// </summary>
~ReferenceCountedObjectBase()
{
// We decrement the global count of objects.
Server.DecrementObjectCount();
// We then immediately test to see if we the conditions
// are right to attempt to terminate this server application.
Server.ExitIf();
}
}
}