2004-02-02 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mono / tests / thread6.cs
1 using System;
2 using System.Threading;
3
4 public class MultiThreadExceptionTest {
5
6         public static int result = 0;
7         
8         public static void ThreadStart1 () {
9                 Console.WriteLine("{0} started", 
10                                   Thread.CurrentThread.Name);
11
12                 try {
13                         try {
14                                 int i = 0;
15                                 try {
16                                         while (true) {
17                                                 Console.WriteLine ("Count: " + i++);
18                                                 Thread.Sleep (100);
19                                         }
20                                 } catch (ThreadAbortException e) {
21                                         Console.WriteLine ("cought exception level 2 " + e.ExceptionState);
22                                         Console.WriteLine (e);
23                                         if ((string)e.ExceptionState == "STATETEST")
24                                                 result |= 1;
25                                         Thread.ResetAbort ();
26                                         throw e;
27                                 }
28                         } catch (ThreadAbortException e) {
29                                 Console.WriteLine ("cought exception level 1 " + e.ExceptionState);
30                                 Console.WriteLine (e);
31                                 if (e.ExceptionState == null)
32                                         result |= 2;
33                         }
34                 } catch (Exception e) {
35                         Console.WriteLine ("cought exception level 0");
36                         Console.WriteLine (e);
37                         result |= 4;
38                 }
39
40                 try {
41                         Thread.ResetAbort ();
42                 } catch (System.Threading.ThreadStateException e) {
43                         result |= 8;                    
44                 }
45                 
46                 Console.WriteLine ("end");
47                 result |= 16;
48         }
49         
50         public static int Main() {
51                 Thread t1 = new Thread(new ThreadStart
52                         (MultiThreadExceptionTest.ThreadStart1));
53                 t1.Name = "Thread 1";
54
55                 Thread.Sleep (100);
56                 
57                 t1.Start();
58
59                 //Thread t0 = Thread.CurrentThread;
60                 //t0.Abort ();
61                 
62                 Thread.Sleep (200);
63                 t1.Abort ("STATETEST");
64
65                 t1.Join ();
66                 Console.WriteLine ("Result: " + result);
67
68                 if (result != 27)
69                         return 1;
70
71                 return 0;
72         }
73 }
74