Skip to content

Instantly share code, notes, and snippets.

@alistairjevans
Last active October 24, 2019 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alistairjevans/91a7abd352d01202b43470d8e0b11356 to your computer and use it in GitHub Desktop.
Save alistairjevans/91a7abd352d01202b43470d8e0b11356 to your computer and use it in GitHub Desktop.
Disposable Object
public class MyDisposableObject : IDisposable, IAsyncDisposable
{
private SqlConnection myResource = new SqlConnection("connection string");
public void Dispose()
{
// Sync dispose on my resource
myResource.Dispose();
}
public async ValueTask DisposeAsync()
{
// Async dispose on the resource
await myResource.DisposeAsync();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment