using System.Threading.Tasks;
class ExampleIncorrectlyStackedProgram
var objOne = new ThrowingAsyncDisposable("1", throwEx: true);
var objTwo = new ThrowingAsyncDisposable("2", throwEx: false);
await using (objOne.ConfigureAwait(false))
await using (objTwo.ConfigureAwait(false))
var objOne = new ThrowingAsyncDisposable("1", throwEx: true);
await using (objOne.ConfigureAwait(false))
var objTwo = new ThrowingAsyncDisposable("2", throwEx: false);
await using (objTwo.ConfigureAwait(false))
public class ThrowingAsyncDisposable : IAsyncDisposable
readonly string _instanceName;
public ThrowingAsyncDisposable(
string instanceName, bool throwEx = false) =>
(_instanceName, _throwEx) = (instanceName, throwEx);
public async ValueTask DisposeAsync()
throw new Exception("Oops...");
Console.WriteLine($"Successfully awaited {_instanceName} async disposable.");