public class MultiThreadExceptionTest {
public static int result = 0;
+ public static object started = new object ();
public static void ThreadStart1 () {
Console.WriteLine("{0} started",
try {
try {
try {
+ lock (started) {
+ Monitor.Pulse (started);
+ }
int i = 0;
try {
while (true) {
// Check that the exception is only rethrown in
// the appropriate catch clauses
+ // This doesn't work currently, see
+ // http://bugzilla.ximian.com/show_bug.cgi?id=68552
+
+ /*
try {
}
catch {}
}
catch (Exception) {
}
+ */
result |= 32;
// Check that the exception is properly rethrown
Console.WriteLine ("end");
result |= 16;
}
+
+ static string regress_78024 ()
+ {
+ try {
+ Thread.CurrentThread.Abort ();
+ } catch (Exception e) {
+ return "Got exception: " + e.Message;
+ } finally {
+ }
+ return "";
+ }
public static int Main() {
-
// Check aborting the current thread
bool aborted = false;
try {
if (!aborted)
return 2;
- Thread t1 = new Thread(new ThreadStart
- (MultiThreadExceptionTest.ThreadStart1));
- t1.Name = "Thread 1";
+ Thread t1 = null;
- Thread.Sleep (100);
-
- t1.Start();
+ lock (started) {
+ t1 = new Thread(new ThreadStart
+ (MultiThreadExceptionTest.ThreadStart1));
+ t1.Name = "Thread 1";
+
+ Thread.Sleep (100);
- Thread.Sleep (200);
+ t1.Start();
+
+ Monitor.Wait (started);
+ }
+
+ Thread.Sleep (100);
+
t1.Abort ("STATETEST");
t1.Join ();
- Console.WriteLine ("Result: " + result);
- if (result != 59)
+ if (result != 59) {
+ Console.WriteLine ("Result: " + result);
return 1;
+ }
+
+ // Test from #68552
+ try {
+ try {
+ Run ();
+ } catch (Exception ex) {
+ }
+
+ return 2;
+ }
+ catch (ThreadAbortException ex) {
+ Thread.ResetAbort ();
+ }
+
+ // Test from #78024
+ try {
+ regress_78024 ();
+ return 3;
+ }
+ catch (ThreadAbortException ex) {
+ Thread.ResetAbort ();
+ }
return 0;
}
+
+ public static void Run ()
+ {
+ try {
+ Thread.CurrentThread.Abort ();
+ } catch (Exception ex) {
+ throw new Exception ("other");
+ }
+ }
}