Initial set of Ward sgen annotations (#5705)
[mono.git] / mono / tests / unload-appdomain-on-shutdown.cs
1 using System;
2 using System.Reflection;
3 using System.Threading;
4
5
6 class Driver {
7         public static void Bla ()
8         {
9                 //DoDomainUnload is invoked as part of the unload sequence, so let's pre jit it here to increase the likehood
10                 //of hanging
11                 var m = typeof (AppDomain).GetMethod ("DoDomainUnload", BindingFlags.Instance | BindingFlags.NonPublic);
12                 if (m != null)
13                         m.MethodHandle.GetFunctionPointer (); 
14         }
15
16         static AppDomain ad;
17         static ManualResetEvent evt = new ManualResetEvent (false);
18         
19         static void UnloadIt ()
20         {
21                 //AppDomain.Unload calls AppDomain::getDomainId () before calling into the runtime, so let's pre jit 
22                 //it here to increase the likehood of hanging
23                 var x = ad.Id;
24                 evt.Set ();
25                 AppDomain.Unload (ad);
26         }
27         static int Main ()
28         {
29                 AppDomain.Unload (AppDomain.CreateDomain ("Warmup unload code"));
30                 Console.WriteLine (".");
31                 ad = AppDomain.CreateDomain ("NewDomain");
32                 ad.DoCallBack (Bla);
33                 var t = new Thread (UnloadIt);
34                 t.IsBackground = true;
35                 t.Start ();
36                 evt.WaitOne ();
37                 return 0;
38         }
39 }