2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mono / tests / delegate3.cs
1 using System;
2 using System.Threading;
3 using System.Runtime.InteropServices;
4 using System.Runtime.Remoting.Messaging;
5
6 class Test {
7         delegate int SimpleDelegate (int a);
8
9         static int cb_state = 0;
10         
11         static int F (int a) {
12                 Console.WriteLine ("Test.F from delegate: " + a);
13                 throw new NotImplementedException ();
14         }
15
16         static void async_callback (IAsyncResult ar)
17         {
18                 AsyncResult ares = (AsyncResult)ar;
19                 AsyncCallback ac = new AsyncCallback (async_callback);
20                 
21                 Console.WriteLine ("Async Callback " + ar.AsyncState);
22                 cb_state++;
23                 SimpleDelegate d = (SimpleDelegate)ares.AsyncDelegate;
24
25                 if (cb_state < 5)
26                         d.BeginInvoke (cb_state, ac, cb_state);
27                 
28                 //throw new NotImplementedException ();
29         }
30         
31         static int Main () {
32                 SimpleDelegate d = new SimpleDelegate (F);
33                 AsyncCallback ac = new AsyncCallback (async_callback);
34                 
35                 IAsyncResult ar1 = d.BeginInvoke (cb_state, ac, cb_state);
36
37                 ar1.AsyncWaitHandle.WaitOne ();
38
39
40                 while (cb_state < 5)
41                         Thread.Sleep (200);
42
43                 return 0;
44         }
45 }