f6d004b9ddb4787009967c90553151b377e6d5e0
[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 desctructor");
15             GetIntDelegate del = new GetIntDelegate (getInt);
16             AsyncCallback ac = new AsyncCallback (async_callback);
17             del.BeginInvoke (ac, "bla");
18     }
19
20     public int getInt () {
21             Console.WriteLine ("getInt in " + AppDomain.CurrentDomain);
22             return 123;
23     }
24 }
25
26 public class main {
27     public static int Main (string [] args) {
28         AppDomain domain = AppDomain.CreateDomain ("newdomain");
29         int i;
30
31         for (i = 0; i < 200; ++i) {
32                 domain.CreateInstanceAndUnwrap (typeof (Test).Assembly.FullName, typeof (Test).FullName);
33         }
34
35         Console.WriteLine ("unloading");
36         AppDomain.Unload (domain);
37         Console.WriteLine ("unloaded");
38
39         GC.Collect ();
40         GC.WaitForPendingFinalizers ();
41
42         Console.WriteLine ("done");
43
44         return 0;
45     }
46 }