遇到过这个exception么? 这个exception是为什么而产生的呢?
下面的代码段来自MSDN, 很有说明性.
简单来说, 就是当进程还想继续执行的时候, 发现自己已经被调用过Abort方法了. 既然自己作为线程已经被中止, 就无法执行罗, 于是exception丢了出来.
下面的代码来自MSDN, 说明问题:
The following example demonstrates aborting a thread. The thread that receives the ThreadAbortException uses the ResetAbort method to cancel the abort request and continue executing.
using System;
using System.Threading;
using System.Security.Permissions;
4:
class ThreadWork {
void DoWork() {
try {
int i=0; i<100; i++) {
);
10: Thread.Sleep(100);
11: }
12: }
catch(ThreadAbortException e) {
);
, e.Message);
16: Thread.ResetAbort();
17: }
);
19: Thread.Sleep(1000);
);
21: }
22: }
23:
class ThreadAbortTest {
void Main() {
new ThreadStart(ThreadWork.DoWork);
new Thread(myThreadDelegate);
28: myThread.Start();
29: Thread.Sleep(100);
);
31: myThread.Abort();
32: myThread.Join();
);
34: }
35: }