2009-06-19 Gonzalo Paniagua Javier <gonzalo@novell.com>
[mono.git] / mcs / tests / test-106.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                         
35                         while (cb_state == 0)
36                                 Thread.Sleep (0);
37                         
38                 } catch (NotImplementedException) {
39                         res = 1;
40                         Console.WriteLine ("received exception ... OK");
41                 }
42
43                 if (cb_state != 1)
44                         return 1;
45                 
46                 if (res != 1)
47                         return 2;
48
49                 return 0;
50         }
51 }