[2020-02] Avoid following invalid pointers in mono_w32process_get_modules on Darwin...
[mono-project.git] / mono / tests / unload-appdomain-on-shutdown.cs
blob9cb13a8b79039b7b923de0cb0bf1d7885e564cef
1 using System;
2 using System.Reflection;
3 using System.Threading;
6 class Driver {
7 public static void Bla ()
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 ();
16 static AppDomain ad;
17 static ManualResetEvent evt = new ManualResetEvent (false);
19 static void UnloadIt ()
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);
27 static int Main ()
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;