-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathCOMObject.cs
61 lines (50 loc) · 1.03 KB
/
COMObject.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Runtime.InteropServices;
namespace TypeAgent;
public class COMObject : IDisposable
{
bool _disposed;
public COMObject()
{
}
~COMObject()
{
Dispose(false);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#pragma warning disable CA1063
void Dispose(bool fromDispose)
{
if (!_disposed)
{
OnDispose();
_disposed = true;
}
}
protected virtual void OnDispose() {}
public static void Release(object value)
{
#pragma warning disable CA1416
if (value != null)
{
Marshal.ReleaseComObject(value);
}
}
public static void Release(IEnumerable<object> values)
{
foreach (object value in values)
{
Release(value);
}
}
public static void ReleaseAll()
{
GC.Collect();
GC.WaitForFullGCComplete();
}
}