Disposable pattern

public class Something : IDisposable {
#region Disposable
    private bool _disposed;
 
    void IDisposable.Dispose() {
        Dispose(true);
        GC.SuppressFinalize(this);
    }
 
    protected void Dispose(bool disposing) {
        if (!_disposed) {
            if (disposing) {
                DisposeManagedResources();
            }
 
            DisposeUnmanagedResources();
            _disposed = true;
        }
    }
 
    protected virtual void DisposeManagedResources() { }
    protected virtual void DisposeUnmanagedResources() { }
 
    ~Something() {
        Dispose(false);
    }
#endregion
}

Comments

Popular posts from this blog

C# Record Serialization

Add timestamp to photo using ImageMagick

Read/write large blob to SQL Server from C#