2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mono / tests / delegate-async-exit.cs
1 using System;
2 using System.Threading;
3 using System.Runtime.InteropServices;
4
5 class foo {
6         delegate void foo_delegate ();
7         
8         static void function () {
9                 Console.WriteLine ("Delegate method");
10         }
11
12         static void async_callback (IAsyncResult ar)
13         {
14                 Console.WriteLine ("Async callback " + ar.AsyncState);
15                 Environment.Exit(0);
16         }
17         
18         public static int Main () {
19                 Environment.ExitCode = 2;
20                 foo_delegate d = new foo_delegate (function);
21                 AsyncCallback ac = new AsyncCallback (async_callback);
22                 IAsyncResult ar1 = d.BeginInvoke (ac, "foo");
23
24                 ar1.AsyncWaitHandle.WaitOne();
25                 d.EndInvoke(ar1);
26
27                 Thread.Sleep(1000);
28                 Console.WriteLine("Main returns");
29                 return 1;
30         }
31 }