Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / finalizer-abort.cs
1
2 using System; 
3 using System.Collections; 
4 using System.Threading;
5
6 public class foo  { 
7         public static LocalDataStoreSlot dataslot = Thread.AllocateDataSlot();
8         public static int final_count=0;
9
10         ~foo() { 
11                 // Demonstrate that this is still the same thread
12                 string ID=(string)Thread.GetData(dataslot);
13                 if(ID==null) {
14                         Console.WriteLine("Set ID: foo");
15                         Thread.SetData(dataslot, "foo");
16                 }
17
18                 // Don't run forever
19                 if(final_count++>10) {
20                         Environment.Exit(0);
21                 }
22
23                 Console.WriteLine("finalizer thread ID: {0}", (string)Thread.GetData(dataslot));
24                 try {
25                         Thread.CurrentThread.Abort();
26                 } catch(ThreadAbortException) {
27                         Console.WriteLine("Aborted!");
28                         // No ResetAbort()!
29                 }
30         } 
31
32         public static int Main() { 
33                 ArrayList list = new ArrayList (); 
34                 Thread.SetData(dataslot, "ID is wibble");
35                 Environment.ExitCode = 2;
36                 while(true) { 
37                         foo instance = new foo(); 
38                         list.Add (new WeakReference(instance)); 
39                         Thread.Sleep (0);
40                 }
41                 return 1;
42         } 
43
44