-
Notifications
You must be signed in to change notification settings - Fork 2
/
Disposable.cs
39 lines (31 loc) · 849 Bytes
/
Disposable.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
using System;
using System.ComponentModel;
namespace DisposableElement
{
public abstract class Disposable : IDisposable
{
IntPtr _handle;
Component _component = new Component();
bool _disposed = false;
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
_component.Dispose();
}
CloseHandle(_handle);
_handle = IntPtr.Zero;
_disposed = true;
}
}
[System.Runtime.InteropServices.DllImport("Kernel32")]
private extern static Boolean CloseHandle(IntPtr handle);
}
}