2 // thread6.cs: Thread abort tests
5 using System
.Threading
;
9 public static int result
= 0;
10 public static object started
= new object ();
12 public static void ThreadStart1 () {
13 Console
.WriteLine("{0} started",
14 Thread
.CurrentThread
.Name
);
20 Monitor
.Pulse (started
);
25 Console
.WriteLine ("Count: " + i
++);
29 catch (ThreadAbortException e
) {
30 Console
.WriteLine ("cought exception level 3 ");
32 // Check that the exception is only rethrown in
33 // the appropriate catch clauses
35 // This doesn't work currently, see
36 // http://bugzilla.ximian.com/show_bug.cgi?id=68552
43 throw new DivideByZeroException ();
50 // Check that the exception is properly rethrown
53 } catch (ThreadAbortException e
) {
54 Console
.WriteLine ("cought exception level 2 " + e
.ExceptionState
);
55 Console
.WriteLine (e
);
56 if ((string)e
.ExceptionState
== "STATETEST")
62 } catch (ThreadAbortException e
) {
63 Console
.WriteLine ("cought exception level 1 " + e
.ExceptionState
);
64 Console
.WriteLine (e
);
65 if (e
.ExceptionState
== null)
68 } catch (Exception e
) {
69 Console
.WriteLine ("cought exception level 0")
70 ; Console
.WriteLine (e
);
71 Console
.WriteLine (e
.StackTrace
);
77 } catch (System
.Threading
.ThreadStateException e
) {
81 Console
.WriteLine ("end");
85 static string regress_78024 ()
88 Thread
.CurrentThread
.Abort ();
89 } catch (Exception e
) {
90 return "Got exception: " + e
.Message
;
96 public static int Main() {
97 return TestDriver
.RunTests (typeof (Tests
));
100 public static int test_0_abort_current () {
101 // Check aborting the current thread
102 bool aborted
= false;
104 Thread
.CurrentThread
.Abort ();
108 Thread
.ResetAbort ();
116 public static int test_0_test_1 () {
120 t1
= new Thread(new ThreadStart
121 (Tests
.ThreadStart1
));
122 t1
.Name
= "Thread 1";
128 Monitor
.Wait (started
);
133 t1
.Abort ("STATETEST");
138 Console
.WriteLine ("Result: " + result
);
145 public static int test_0_regress_68552 () {
149 } catch (Exception ex
) {
154 catch (ThreadAbortException ex
) {
155 Thread
.ResetAbort ();
161 public static int test_0_regress_78024 () {
166 catch (ThreadAbortException ex
) {
167 Thread
.ResetAbort ();
173 public class CBO
: ContextBoundObject
{
175 Thread
.CurrentThread
.Abort ("FOO");
179 public static int test_0_regress_539394 () {
180 // Check that a ThreadAbortException thrown through remoting retains its
182 AppDomain d
= AppDomain
.CreateDomain ("test");
183 CBO obj
= (CBO
)d
.CreateInstanceFromAndUnwrap (typeof (Tests
).Assembly
.Location
, "Tests/CBO");
184 bool success
= false;
186 Thread t
= new Thread (delegate () {
189 } catch (ThreadAbortException ex
) {
190 if ((string)ex
.ExceptionState
== "FOO")
198 return success
? 0 : 1;
201 public static void Run ()
204 Thread
.CurrentThread
.Abort ();
205 } catch (Exception ex
) {
206 throw new Exception ("other");