2 using System.Threading;
8 Console.WriteLine ("FINALIZING IN DOMAIN " + AppDomain.CurrentDomain.FriendlyName + ": " + AppDomain.CurrentDomain.IsFinalizingForUnload ());
13 public class SlowFinalize {
16 Console.WriteLine ("FINALIZE1.");
20 catch (Exception ex) {
21 Console.WriteLine ("A: " + ex);
23 Console.WriteLine ("FINALIZE2.");
28 public class AThread {
31 new Thread (new ThreadStart (Run)).Start ();
39 catch (ThreadAbortException ex) {
40 Console.WriteLine ("Thread aborted correctly.");
45 // A Thread which refuses to die
46 public class BThread : MarshalByRefObject {
51 new Thread (new ThreadStart (Run)).Start ();
63 catch (ThreadAbortException ex) {
70 public class UnloadThread {
74 public UnloadThread (AppDomain domain) {
79 Console.WriteLine ("UNLOAD1");
80 AppDomain.Unload (domain);
81 Console.WriteLine ("UNLOAD2");
87 public static int Main() {
88 return TestDriver.RunTests (typeof (Tests));
91 public static int test_0_unload () {
92 for (int i = 0; i < 10; ++i) {
93 AppDomain appDomain = AppDomain.CreateDomain("Test-unload" + i);
94 AppDomain.Unload(appDomain);
100 public static int test_0_unload_default () {
102 AppDomain.Unload (Thread.GetDomain ());
104 catch (CannotUnloadAppDomainException) {
110 public static int test_0_unload_after_unload () {
111 AppDomain domain = AppDomain.CreateDomain ("Test2");
112 AppDomain.Unload (domain);
115 AppDomain.Unload (domain);
124 public static int test_0_is_finalizing () {
125 AppDomain domain = AppDomain.CreateDomain ("Test-is-finalizing");
126 object o = domain.CreateInstanceFromAndUnwrap (typeof (Tests).Assembly.Location, "Foo");
128 if (domain.IsFinalizingForUnload ())
131 AppDomain.Unload (domain);
136 public static int test_0_unload_with_active_threads () {
137 AppDomain domain = AppDomain.CreateDomain ("Test3");
138 object o = domain.CreateInstanceFromAndUnwrap (typeof (Tests).Assembly.Location, "AThread");
141 AppDomain.Unload (domain);
146 public static int test_0_unload_with_active_threads_timeout () {
147 AppDomain domain = AppDomain.CreateDomain ("Test4");
148 BThread o = (BThread)domain.CreateInstanceFromAndUnwrap (typeof (Tests).Assembly.Location, "BThread");
152 AppDomain.Unload (domain);
157 AppDomain.Unload (domain);
164 // FIXME: This does not work yet, because the thread is finalized too
167 public static int test_0_unload_during_unload () {
168 AppDomain domain = AppDomain.CreateDomain ("Test3");
169 object o = domain.CreateInstanceFromAndUnwrap (typeof (Tests).Assembly.Location, "SlowFinalize");
171 UnloadThread t = new UnloadThread (domain);
173 // Start unloading in a separate thread
174 new Thread (new ThreadStart (t.Run)).Start ();
179 AppDomain.Unload (domain);
182 Console.WriteLine ("OK");