using System.Threading.Tasks;
public static async Task Main()
Console.WriteLine("Started");
Console.WriteLine("IsCompleted: {0}", task.IsCompleted);
Console.WriteLine("IsCanceled: {0}", task.IsCanceled);
Console.WriteLine("IsFaulted: {0}", task.IsFaulted);
Console.WriteLine("Exception: {0}", task.Exception);
Console.WriteLine("Ended");
private static async Task<IDisposable> GetDisposableAsync()
return new TestDisposable();
private static async Task<int> DivideByZeroAsync()
await Task.Delay(TimeSpan.FromSeconds(1));
private static async Task TestAsync()
using (await GetDisposableAsync())
await DivideByZeroAsync();
Console.WriteLine("Caught exception {0}", e);
public class TestDisposable : IDisposable
Console.WriteLine("Constructed");
Console.WriteLine("Disposed");