Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / appdomain-async-invoke.cs
1 using System;
2 using System.Threading;
3 using System.Runtime.Remoting;
4
5 public class Test : MarshalByRefObject {
6     delegate int GetIntDelegate ();
7
8     static void async_callback (IAsyncResult ar)
9     {
10             Console.WriteLine ("Async Callback in domain " + AppDomain.CurrentDomain + " " + ar.AsyncState);
11     }
12
13     ~Test () {
14             Console.WriteLine ("in test destructor");
15             GetIntDelegate del = new GetIntDelegate (getInt);
16             AsyncCallback ac = new AsyncCallback (async_callback);
17             if (del.BeginInvoke (ac, "bla") == null) {
18                     Console.WriteLine ("async result is null");
19                     Environment.Exit (1);
20             }
21     }
22
23     public int getInt () {
24             Console.WriteLine ("getInt in " + AppDomain.CurrentDomain);
25             return 123;
26     }
27 }
28
29 public class main {
30     public static int Main (string [] args) {
31         AppDomain domain = AppDomain.CreateDomain ("newdomain");
32         int i;
33
34         for (i = 0; i < 200; ++i) {
35                 domain.CreateInstanceAndUnwrap (typeof (Test).Assembly.FullName, typeof (Test).FullName);
36         }
37
38         Console.WriteLine ("unloading");
39         AppDomain.Unload (domain);
40         Console.WriteLine ("unloaded");
41
42         GC.Collect ();
43         GC.WaitForPendingFinalizers ();
44
45         Console.WriteLine ("done");
46
47         return 0;
48     }
49 }