/
main-returns-background-abort-resetabort.cs
64 lines (60 loc) · 1.5 KB
/
main-returns-background-abort-resetabort.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
using System;
using System.Threading;
public class foo {
public static void Main() {
Thread thr=new Thread(new ThreadStart(foo.thread));
thr.IsBackground=true;
thr.Start();
Thread.Sleep(600);
Console.WriteLine("Aborting child thread");
thr.Abort();
Thread.Sleep(600);
Console.WriteLine("Main thread returns");
}
public static void thread() {
try {
Console.WriteLine("Thread running");
Thread.Sleep(500);
} catch(ThreadAbortException) {
Thread.ResetAbort();
Console.WriteLine("Abort reset!");
} finally {
Console.WriteLine("ThreadAbortException finally");
}
try {
Console.WriteLine("Thread running");
Thread.Sleep(500);
} catch(ThreadAbortException) {
Thread.ResetAbort();
Console.WriteLine("Abort reset!");
} finally {
Console.WriteLine("ThreadAbortException finally");
}
try {
Console.WriteLine("Thread running");
Thread.Sleep(500);
} catch(ThreadAbortException) {
Thread.ResetAbort();
Console.WriteLine("Abort reset!");
} finally {
Console.WriteLine("ThreadAbortException finally");
}
try {
Console.WriteLine("Thread running");
Thread.Sleep(500);
} catch(ThreadAbortException) {
Thread.ResetAbort();
Console.WriteLine("Abort reset!");
} finally {
Console.WriteLine("ThreadAbortException finally");
}
try {
Console.WriteLine("Thread running");
} catch(ThreadAbortException) {
Thread.ResetAbort();
Console.WriteLine("Abort reset!");
} finally {
Console.WriteLine("ThreadAbortException finally");
}
}
}