Last active
December 1, 2022 14:49
-
-
Save sandord/400557 to your computer and use it in GitHub Desktop.
Disposable pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyClass : IDisposable | |
{ | |
/// <summary> | |
/// Finalizes an instance of the <see cref="MyClass"/> class. Releases unmanaged | |
/// resources and performs other cleanup operations before the current instance is | |
/// reclaimed by garbage collection. | |
/// </summary> | |
~MyClass() | |
{ | |
this.Dispose(false); | |
} | |
/// <summary> | |
/// Performs application-defined tasks associated with freeing, releasing, or resetting | |
/// unmanaged resources. | |
/// </summary> | |
public void Dispose() | |
{ | |
this.Dispose(true); | |
GC.SuppressFinalize(this); | |
} | |
/// <summary> | |
/// Releases unmanaged and - optionally - managed resources. | |
/// </summary> | |
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> | |
protected virtual void Dispose(bool disposing) | |
{ | |
if (disposing) | |
{ | |
// Release managed resources. | |
} | |
// Release unmanaged resources. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment