Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / delegate2.cs
1 using System;
2 using System.Threading;
3 using System.Runtime.InteropServices;
4
5 class Test {
6         delegate int SimpleDelegate (int a);
7
8         static int cb_state = 0;
9         
10         static int F (int a) {
11                 Console.WriteLine ("Test.F from delegate: " + a);
12                 throw new NotImplementedException ();
13         }
14
15         static void async_callback (IAsyncResult ar)
16         {
17                 Console.WriteLine ("Async Callback " + ar.AsyncState);
18                 cb_state = 1;
19                 throw new NotImplementedException ();
20         }
21         
22         static int Main () {
23                 SimpleDelegate d = new SimpleDelegate (F);
24                 AsyncCallback ac = new AsyncCallback (async_callback);
25                 string state1 = "STATE1";
26                 int res = 0;
27                 
28                 IAsyncResult ar1 = d.BeginInvoke (1, ac, state1);
29
30                 ar1.AsyncWaitHandle.WaitOne ();
31
32                 try {
33                         res = d.EndInvoke (ar1);
34                 } catch (NotImplementedException) {
35                         res = 1;
36                         Console.WriteLine ("received exception ... OK");
37                 }
38
39                 while (cb_state == 0)
40                         Thread.Sleep (0);
41                 
42                 if (cb_state != 1)
43                         return 1;
44                 
45                 if (res != 1)
46                         return 2;
47
48                 return 0;
49         }
50 }