[mini] Fix test compiling when running !MOBILE
[mono.git] / mcs / tests / test-async-01.cs
1 using System;
2 using System.Threading;
3 using System.Threading.Tasks;
4
5 class Program
6 {
7         static ManualResetEvent master_mre = new ManualResetEvent (false);
8         static ManualResetEvent async_mre = new ManualResetEvent (false);
9
10         static int pos;
11
12         public static int Main ()
13         {
14                 pos = 0;
15                 TestAsync ();
16
17                 if (pos != 1)
18                         throw new ApplicationException (pos.ToString ());
19
20                 pos = 2;
21
22                 master_mre.Set ();
23
24                 if (!async_mre.WaitOne (3000))
25                         return 1;
26
27                 if (pos != 4)
28                         throw new ApplicationException (pos.ToString ());
29
30                 return 0;
31         }
32
33         static async void TestAsync ()
34         {
35                 pos = 1;
36
37                 await RunAsync ().ConfigureAwait (false);
38
39                 if (pos != 3)
40                         throw new ApplicationException (pos.ToString ());
41
42                 pos = 4;
43                 async_mre.Set ();
44         }
45
46         static Task RunAsync ()
47         {
48                 return Task.Factory.StartNew (() => {
49                         master_mre.WaitOne ();
50                         Console.WriteLine ("Hello async");
51                         if (pos != 2)
52                                 throw new ApplicationException (pos.ToString ());
53
54                         pos = 3;
55                 });
56         }
57 }