2 using System.Threading;
3 using System.Threading.Tasks;
7 static async Task<int> TestCanceled()
9 await Task.FromResult(1);
10 throw new OperationCanceledException();
13 static async Task TestCanceled_2()
15 await Task.FromResult(1);
16 throw new OperationCanceledException();
19 static async Task<int> TestException()
21 await Task.FromResult(1);
22 throw new ApplicationException();
25 public static int Main()
27 bool canceled = false;
28 var t = TestCanceled().ContinueWith(l =>
30 canceled = l.IsCanceled;
31 }, TaskContinuationOptions.ExecuteSynchronously);
38 if (t.Exception != null)
41 t = TestCanceled_2().ContinueWith(l =>
43 canceled = l.IsCanceled;
44 }, TaskContinuationOptions.ExecuteSynchronously);
51 if (t.Exception != null)
55 bool has_exception = false;
56 t = TestException().ContinueWith(l =>
58 faulted = l.IsFaulted;
59 has_exception = l.Exception != null; // Has to observe it or will throw on shutdown
60 }, TaskContinuationOptions.ExecuteSynchronously);
68 if (t.Exception != null)
71 Console.WriteLine("ok");