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