Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public abstract class Disposable : IRealDisposable {
- private volatile int isDisposed;
- public bool IsDisposed {
- get => this.isDisposed != 0;
- }
- protected Disposable(bool canDisposeInDestructor = true) {
- if (!canDisposeInDestructor) {
- GC.SuppressFinalize(this);
- }
- }
- ~Disposable() {
- this.Dispose(false);
- }
- public void Dispose() {
- this.Dispose(true);
- }
- public void Dispose(bool isDisposing) {
- if (Interlocked.CompareExchange(ref this.isDisposed, 1, 0) != 0)
- return;
- GC.SuppressFinalize(this);
- this.OnDispose(isDisposing);
- }
- protected abstract void OnDispose(bool isDisposing);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement