static async Task Main() { await using var exampleAsyncDisposable = new ExampleAsyncDisposable(); // Interact with the exampleAsyncDisposable instance. Console.ReadLine(); }
static async Task Main() { var exampleAsyncDisposable = new ExampleAsyncDisposable(); await using (exampleAsyncDisposable.ConfigureAwait(false)) { // Interact with the exampleAsyncDisposable instance. } Console.ReadLine(); }
static async Task Main() { var objOne = new ExampleAsyncDisposable(); // Exception thrown on .ctor var objTwo = new AnotherAsyncDisposable(); await using (objOne.ConfigureAwait(false)) await using (objTwo.ConfigureAwait(false)) { // Only objOne has its DisposeAsync called. } Console.ReadLine(); }
static async Task Main() { var objOne = new ExampleAsyncDisposable(); await using var ignored1 = objOne.ConfigureAwait(false); var objTwo = new ExampleAsyncDisposable(); await using var ignored2 = objTwo.ConfigureAwait(false); // Interact with objOne and/or objTwo instance(s). Console.ReadLine(); }
static async Task Main() { var objOne = new ExampleAsyncDisposable(); await using objOne.ConfigureAwait(false); // Interact with the objOne instance. var objTwo = new ExampleAsyncDisposable(); await using objTwo.ConfigureAwait(false)) { // Interact with the objTwo instance. } Console.ReadLine(); }