Make Main method public
[mono.git] / mcs / tests / test-async-06.cs
1 // Compiler options: -langversion:future
2
3 using System;
4 using System.Threading;
5 using System.Threading.Tasks;
6
7 class Program
8 {
9         public static int Main ()
10         {
11                 var mre = new ManualResetEvent (false);
12                 var mre_l = new ManualResetEvent (false);
13
14                 Action a = async () => {
15                         await Task.Factory.StartNew (() => {
16                                 if (!mre_l.WaitOne (3000))
17                                         throw new ApplicationException ("1");
18                         });
19
20                         if (mre_l.WaitOne ())
21                                 mre.Set ();
22                 };
23
24                 a ();
25                 mre_l.Set ();
26                 if (!mre.WaitOne (3000))
27                         return 1;
28
29                 mre.Reset ();
30                 mre_l.Reset ();
31
32                 Action a2 = async delegate {
33                         await Task.Factory.StartNew (() => {
34                                 if (!mre_l.WaitOne (3000))
35                                         throw new ApplicationException ("2");
36                         });
37
38                         if (mre_l.WaitOne ())
39                                 mre.Set ();
40                 };
41
42                 a2 ();
43                 mre_l.Set ();
44                 if (!mre.WaitOne (3000))
45                         return 2;
46
47                 mre_l.Reset ();
48
49                 Func<string, Task<string>> f = async l => {
50                         var t = await Task.Factory.StartNew (() => {
51                                 if (!mre_l.WaitOne (3000))
52                                         throw new ApplicationException ("3");
53
54                                 return l;
55                         });
56
57                         return t;
58                 };
59
60                 var r = f ("a");
61                 mre_l.Set ();
62                 if (!r.Wait (3000))
63                         return 3;
64
65                 if (r.Result != "a")
66                         return 31;
67
68                 mre_l.Reset ();
69
70                 Func<decimal, Task<decimal>> f2 = async delegate (decimal l) {
71                         var t = await Task.Factory.StartNew (() => {
72                                 if (!mre_l.WaitOne (3000))
73                                         throw new ApplicationException ("4");
74
75                                 return l;
76                         });
77
78                         return t;
79                 };
80
81                 var r2 = f2 (decimal.MaxValue);
82                 mre_l.Set ();
83                 if (!r2.Wait (3000))
84                         return 4;
85
86                 if (r2.Result != decimal.MaxValue)
87                         return 41;
88
89                 f2 = async delegate (decimal l) {
90                         return l;
91                 };
92
93                 r2 = f2 (88);
94                 if (r2.Result != 88)
95                         return 5;
96
97                 return 0;
98         }
99 }