[ilasm] Don't break arguments compatiblity
[mono-project.git] / mcs / tests / test-async-06.cs
bloba6c3ac9175a975360b6ef661624d3c2f9d7a6f2e
1 using System;
2 using System.Threading;
3 using System.Threading.Tasks;
5 class Program
7 public static int Main ()
9 var mre = new ManualResetEvent (false);
10 var mre_l = new ManualResetEvent (false);
12 Action a = async () => {
13 await Task.Factory.StartNew (() => {
14 if (!mre_l.WaitOne (3000))
15 throw new ApplicationException ("1");
16 }).ConfigureAwait (false);
18 if (mre_l.WaitOne ())
19 mre.Set ();
22 a ();
23 mre_l.Set ();
24 if (!mre.WaitOne (3000))
25 return 1;
27 mre.Reset ();
28 mre_l.Reset ();
30 Action a2 = async delegate {
31 await Task.Factory.StartNew (() => {
32 if (!mre_l.WaitOne (3000))
33 throw new ApplicationException ("2");
34 }).ConfigureAwait (false);
36 if (mre_l.WaitOne ())
37 mre.Set ();
40 a2 ();
41 mre_l.Set ();
42 if (!mre.WaitOne (3000))
43 return 2;
45 mre_l.Reset ();
47 Func<string, Task<string>> f = async l => {
48 var t = await Task.Factory.StartNew (() => {
49 if (!mre_l.WaitOne (3000))
50 throw new ApplicationException ("3");
52 return l;
53 }).ConfigureAwait (false);
55 return t;
58 var r = f ("a");
59 mre_l.Set ();
60 if (!r.Wait (3000))
61 return 3;
63 if (r.Result != "a")
64 return 31;
66 mre_l.Reset ();
68 Func<decimal, Task<decimal>> f2 = async delegate (decimal l) {
69 var t = await Task.Factory.StartNew (() => {
70 if (!mre_l.WaitOne (3000))
71 throw new ApplicationException ("4");
73 return l;
74 }).ConfigureAwait (false);
76 return t;
79 var r2 = f2 (decimal.MaxValue);
80 mre_l.Set ();
81 if (!r2.Wait (3000))
82 return 4;
84 if (r2.Result != decimal.MaxValue)
85 return 41;
87 f2 = async delegate (decimal l) {
88 return l;
91 r2 = f2 (88);
92 if (r2.Result != 88)
93 return 5;
95 return 0;