2 using System
.Threading
.Tasks
;
3 using System
.Threading
;
4 using System
.Reflection
;
6 using System
.Collections
.Generic
;
8 class Base
: IDisposable
10 protected static int dispose_counter
;
12 public void Dispose ()
20 async Task
<int> SwitchTest_1 ()
22 switch (await Task
.Factory
.StartNew (() => "X").ConfigureAwait (false)) {
38 async Task
<int> Using_1 ()
40 using (Base a
= await Task
.Factory
.StartNew (() => new Base ()).ConfigureAwait (false),
41 b
= await Task
.Factory
.StartNew (() => new Tester ()).ConfigureAwait (false),
42 c
= await Task
.Factory
.StartNew (() => new Base ()).ConfigureAwait (false),
43 d
= await Task
.Factory
.StartNew (() => new Base ()).ConfigureAwait (false)) {
46 if (dispose_counter
!= 4)
52 async Task
<int> Foreach_1 ()
55 foreach (var e
in await Task
.Factory
.StartNew (() => new List
<int> () { 1, 2, 3 }
).ConfigureAwait (false)) {
62 async Task
<int> Foreach_2 ()
65 foreach (var e
in await Task
.Factory
.StartNew (() => new List
<int> () { 1, 2, 3 }
).ConfigureAwait (false)) {
73 static bool RunTest (MethodInfo test
)
75 Console
.Write ("Running test {0, -25}", test
.Name
);
77 Task t
= test
.Invoke (new Tester (), null) as Task
;
78 if (!Task
.WaitAll (new[] { t }
, 1000)) {
79 Console
.WriteLine ("FAILED (Timeout)");
83 var ti
= t
as Task
<int>;
86 Console
.WriteLine ("FAILED (Result={0})", ti
.Result
);
90 var tb
= t
as Task
<bool>;
93 Console
.WriteLine ("FAILED (Result={0})", tb
.Result
);
99 Console
.WriteLine ("OK");
101 } catch (Exception e
) {
102 Console
.WriteLine ("FAILED");
103 Console
.WriteLine (e
.ToString ());
108 public static int Main ()
110 var tests
= from test
in typeof (Tester
).GetMethods (BindingFlags
.Instance
| BindingFlags
.NonPublic
| BindingFlags
.DeclaredOnly
)
111 where test
.GetParameters ().Length
== 0
113 select RunTest (test
);
115 int failures
= tests
.Count (a
=> !a
);
116 Console
.WriteLine (failures
+ " tests failed");