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