2007-12-06 Jb Evain <jbevain@novell.com>
[mono.git] / mono / tests / delegate2.cs
blob52b5f61d9f1690d9d22b27392ee0c8d34754afa0
1 using System;
2 using System.Threading;
3 using System.Runtime.InteropServices;
5 class Test {
6 delegate int SimpleDelegate (int a);
8 static int cb_state = 0;
10 static int F (int a) {
11 Console.WriteLine ("Test.F from delegate: " + a);
12 throw new NotImplementedException ();
15 static void async_callback (IAsyncResult ar)
17 Console.WriteLine ("Async Callback " + ar.AsyncState);
18 cb_state = 1;
19 throw new NotImplementedException ();
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;
28 IAsyncResult ar1 = d.BeginInvoke (1, ac, state1);
30 ar1.AsyncWaitHandle.WaitOne ();
32 try {
33 res = d.EndInvoke (ar1);
34 } catch (NotImplementedException) {
35 res = 1;
36 Console.WriteLine ("received exception ... OK");
39 while (cb_state == 0)
40 Thread.Sleep (0);
42 if (cb_state != 1)
43 return 1;
45 if (res != 1)
46 return 2;
48 return 0;