Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / appdomain-unload-callback.cs
1 using System;
2 using System.Threading;
3
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
9 {
10         static void UnloadHook (object obj, EventArgs args)
11         {
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 ();
19                 };
20                 f.BeginInvoke (1, null, null);
21                 evt.WaitOne ();
22                 Console.WriteLine ("Hook done");
23         }
24
25         static void OtherDomain()
26         {
27                 AppDomain app = AppDomain.CurrentDomain;
28                 Console.WriteLine ("Now I'm on {0}", app);
29                 app.DomainUnload += Driver.UnloadHook;
30         }
31
32         static int Main ()
33         {
34                 AppDomain app = AppDomain.CreateDomain ("Foo");
35                 Console.WriteLine ("I'm on {0}", AppDomain.CurrentDomain);
36                 app.DoCallBack (Driver.OtherDomain );
37
38                 Thread.Sleep (1);
39                 AppDomain.Unload (app);
40                 Thread.Sleep (1);
41                 return 0;
42         }
43 }
44