Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CriticalHandle.cs
Go to the documentation of this file.
2
4
6{
7 protected IntPtr handle;
8
9 private bool _isClosed;
10
11 public bool IsClosed => _isClosed;
12
13 public abstract bool IsInvalid { get; }
14
15 protected CriticalHandle(IntPtr invalidHandleValue)
16 {
17 handle = invalidHandleValue;
18 }
19
21 {
22 Dispose(disposing: false);
23 }
24
25 private void Cleanup()
26 {
27 if (!IsClosed)
28 {
29 _isClosed = true;
30 if (!IsInvalid)
31 {
32 int lastPInvokeError = Marshal.GetLastPInvokeError();
34 Marshal.SetLastPInvokeError(lastPInvokeError);
35 GC.SuppressFinalize(this);
36 }
37 }
38 }
39
40 protected void SetHandle(IntPtr handle)
41 {
42 this.handle = handle;
43 }
44
45 public void Close()
46 {
47 Dispose(disposing: true);
48 }
49
50 public void Dispose()
51 {
52 Dispose(disposing: true);
53 }
54
55 protected virtual void Dispose(bool disposing)
56 {
57 Cleanup();
58 }
59
60 public void SetHandleAsInvalid()
61 {
62 _isClosed = true;
63 GC.SuppressFinalize(this);
64 }
65
66 protected abstract bool ReleaseHandle();
67}
static void SuppressFinalize(object obj)
Definition GC.cs:202
Definition GC.cs:8
static void SetLastPInvokeError(int error)