/
thread6.cs
107 lines (87 loc) · 2.07 KB
/
thread6.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Threading;
public class MultiThreadExceptionTest {
public static int result = 0;
public static void ThreadStart1 () {
Console.WriteLine("{0} started",
Thread.CurrentThread.Name);
try {
try {
try {
int i = 0;
try {
while (true) {
Console.WriteLine ("Count: " + i++);
Thread.Sleep (100);
}
}
catch (ThreadAbortException e) {
Console.WriteLine ("cought exception level 3 ");
// Check that the exception is only rethrown in
// the appropriate catch clauses
try {
}
catch {}
try {
throw new DivideByZeroException ();
}
catch (Exception) {
}
result |= 32;
// Check that the exception is properly rethrown
}
result = 255;
} catch (ThreadAbortException e) {
Console.WriteLine ("cought exception level 2 " + e.ExceptionState);
Console.WriteLine (e);
if ((string)e.ExceptionState == "STATETEST")
result |= 1;
Thread.ResetAbort ();
throw e;
}
} catch (ThreadAbortException e) {
Console.WriteLine ("cought exception level 1 " + e.ExceptionState);
Console.WriteLine (e);
if (e.ExceptionState == null)
result |= 2;
}
} catch (Exception e) {
Console.WriteLine ("cought exception level 0")
; Console.WriteLine (e);
Console.WriteLine (e.StackTrace);
result |= 4;
}
try {
Thread.ResetAbort ();
} catch (System.Threading.ThreadStateException e) {
result |= 8;
}
Console.WriteLine ("end");
result |= 16;
}
public static int Main() {
// Check aborting the current thread
bool aborted = false;
try {
Thread.CurrentThread.Abort ();
}
catch {
aborted = true;
Thread.ResetAbort ();
}
if (!aborted)
return 2;
Thread t1 = new Thread(new ThreadStart
(MultiThreadExceptionTest.ThreadStart1));
t1.Name = "Thread 1";
Thread.Sleep (100);
t1.Start();
Thread.Sleep (200);
t1.Abort ("STATETEST");
t1.Join ();
Console.WriteLine ("Result: " + result);
if (result != 59)
return 1;
return 0;
}
}