microsoft/TypeAgent

Public

mirrored from https://github.com/microsoft/TypeAgentAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
749865d4258b084443a56bffcfa490ef2cdbe80d

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

dotnet/email/COMObject.cs

53lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4using System.Runtime.InteropServices;
5
6namespace TypeAgent;
7
8public class COMObject : IDisposable
9{
10 bool _disposed;
11
12 public COMObject()
13 {
14 }
15
16 ~COMObject()
17 {
18 Dispose(false);
19 }
20
21 public void Dispose()
22 {
23 Dispose(true);
24 GC.SuppressFinalize(this);
25 }
26
27#pragma warning disable CA1063
28 void Dispose(bool fromDispose)
29 {
30 if (!_disposed)
31 {
32 OnDispose();
33 _disposed = true;
34 }
35 }
36
37 protected virtual void OnDispose() {}
38
39 public static void Release(object value)
40 {
41#pragma warning disable CA1416
42 if (value != null)
43 {
44 Marshal.ReleaseComObject(value);
45 }
46 }
47
48 public static void ReleaseAll()
49 {
50 GC.Collect();
51 GC.WaitForFullGCComplete();
52 }
53}
54