[tests] Test loading references from LoadFrom and LoadFile contexts
[mono-project.git] / mono / tests / appdomain-unload-callback.cs
blobde44c923bf2b36a34a55e73f4333f52941603048
1 using System;
2 using System.Threading;
4 /*
5 This test checks if the AddDomain::DomainUnload event is processed with
6 a fully working domain. In special if the threadpool remains operational.
7 */
8 class Driver
10 static void UnloadHook (object obj, EventArgs args)
12 ManualResetEvent evt = new ManualResetEvent (false);
13 Console.WriteLine ("On the UnloadHook");
14 if (Environment.HasShutdownStarted)
15 throw new Exception ("Environment.HasShutdownStarted must not be true");
16 Action<int> f = (int x) => {
17 evt.WaitOne (1000);
18 evt.Set ();
20 f.BeginInvoke (1, null, null);
21 evt.WaitOne ();
22 Console.WriteLine ("Hook done");
25 static void OtherDomain()
27 AppDomain app = AppDomain.CurrentDomain;
28 Console.WriteLine ("Now I'm on {0}", app);
29 app.DomainUnload += Driver.UnloadHook;
32 static int Main ()
34 AppDomain app = AppDomain.CreateDomain ("Foo");
35 Console.WriteLine ("I'm on {0}", AppDomain.CurrentDomain);
36 app.DoCallBack (Driver.OtherDomain );
38 Thread.Sleep (1);
39 AppDomain.Unload (app);
40 Thread.Sleep (1);
41 return 0;