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.");
46 // A Thread which refuses to die
47 public class BThread {
50 new Thread (new ThreadStart (Run)).Start ();
58 catch (ThreadAbortException ex) {
59 Thread.Sleep (1000000000);
64 public class UnloadThread {
68 public UnloadThread (AppDomain domain) {
73 Console.WriteLine ("UNLOAD1");
74 AppDomain.Unload (domain);
75 Console.WriteLine ("UNLOAD2");
81 public static int Main() {
82 return TestDriver.RunTests (typeof (Tests));
85 public static int test_0_unload () {
86 for (int i = 0; i < 10; ++i) {
87 AppDomain appDomain = AppDomain.CreateDomain("Test-unload" + i);
88 AppDomain.Unload(appDomain);
94 public static int test_0_unload_default () {
96 AppDomain.Unload (Thread.GetDomain ());
98 catch (CannotUnloadAppDomainException) {
104 public static int test_0_unload_after_unload () {
105 AppDomain domain = AppDomain.CreateDomain ("Test2");
106 AppDomain.Unload (domain);
109 AppDomain.Unload (domain);
118 public static int test_0_is_finalizing () {
119 AppDomain domain = AppDomain.CreateDomain ("Test-is-finalizing");
120 object o = domain.CreateInstanceFromAndUnwrap (typeof (Tests).Assembly.Location, "Foo");
122 if (domain.IsFinalizingForUnload ())
125 AppDomain.Unload (domain);
130 public static int test_0_unload_with_active_threads () {
131 AppDomain domain = AppDomain.CreateDomain ("Test3");
132 object o = domain.CreateInstanceFromAndUnwrap (typeof (Tests).Assembly.Location, "AThread");
135 AppDomain.Unload (domain);
140 public static int test_0_unload_with_active_threads_timeout () {
141 AppDomain domain = AppDomain.CreateDomain ("Test4");
142 object o = domain.CreateInstanceFromAndUnwrap (typeof (Tests).Assembly.Location, "BThread");
146 AppDomain.Unload (domain);
155 // FIXME: This does not work yet, because the thread is finalized too
158 public static int test_0_unload_during_unload () {
159 AppDomain domain = AppDomain.CreateDomain ("Test3");
160 object o = domain.CreateInstanceFromAndUnwrap (typeof (Tests).Assembly.Location, "SlowFinalize");
162 UnloadThread t = new UnloadThread (domain);
164 // Start unloading in a separate thread
165 new Thread (new ThreadStart (t.Run)).Start ();
170 AppDomain.Unload (domain);
173 Console.WriteLine ("OK");