Merge pull request #901 from Blewzman/FixAggregateExceptionGetBaseException
[mono.git] / mcs / tests / test-async-59.cs
1 using System;
2 using System.Threading;
3 using System.Threading.Tasks;
4
5 class X
6 {
7         static bool unobserved;
8
9         public static int Main ()
10         {
11                 TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
12                 try {
13                         Test ().Wait ();
14
15                         GC.Collect ();
16                         GC.WaitForPendingFinalizers ();
17                         if (unobserved)
18                                 return 1;
19
20                         return 0;
21                 } finally {
22                         TaskScheduler.UnobservedTaskException -= TaskScheduler_UnobservedTaskException;
23                 }
24         }
25
26         static void TaskScheduler_UnobservedTaskException (object sender, UnobservedTaskExceptionEventArgs e)
27         {
28                 unobserved = true;
29                 Console.WriteLine ("unobserved");
30         }
31
32         static async Task Test ()
33         {
34                 try {
35                         await ThrowAsync ();
36                 } catch {                       
37                 }
38         }
39
40         static async Task ThrowAsync()
41         {
42                 await Task.Delay (5);
43
44                 throw new Exception ("boom");
45         }
46 }