Merge pull request #733 from amoiseev-softheme/bugfix/monofix
[mono.git] / mcs / tests / test-async-19.cs
1 // Compiler options: -langversion:future
2
3 using System;
4 using System.Threading;
5 using System.Threading.Tasks;
6
7 class C
8 {
9         static ManualResetEvent caught = new ManualResetEvent (false);
10
11         static async void Test (ManualResetEvent mre)
12         {
13                 var a = Task.Factory.StartNew (() => {
14                         if (mre.WaitOne (1000))
15                                 throw new ApplicationException ();
16                 });
17
18                 await a.ConfigureAwait (false);
19         }
20
21         public static int Main ()
22         {
23                 ManualResetEvent mre = new ManualResetEvent (false);
24                 Test (mre);
25
26                 var handler = new UnhandledExceptionEventHandler (CurrentDomain_UnhandledException);
27                 AppDomain.CurrentDomain.UnhandledException += handler;
28                 try {
29                         mre.Set ();
30
31                         if (!caught.WaitOne (1000))
32                                 return 1;
33
34                         return 0;
35                 } finally {
36                         AppDomain.CurrentDomain.UnhandledException -= handler;
37                 }
38         }
39
40         static void CurrentDomain_UnhandledException (object sender, UnhandledExceptionEventArgs e)
41         {
42                 if (e.ExceptionObject is ApplicationException)
43                         caught.Set ();
44         }
45 }