作者leicheong (睡魔)
看板C_Sharp
标题Re: [问题] about multi-thread
时间Wed Sep 26 18:56:22 2007
※ 引述《horngsh (要公理要正义)》之铭言:
: 各位先进好:
: 弟对THREAD有些不解的地方,盼望有能人可以为我解惑, 感恩!
: 文述如下:
: You might wish to kill a thread in reaction to an event,
: such as the user clicking the Cancel button.
: The event handler for the Cancel button might be in thread
: t1, and the event it is canceling might be in thread t2.
: In your event handler, you can call Abort on t1:
: t1.Abort();
: An exception will be raised in t1's currently running method
: that t1 can catch.
: 我的疑问是当T1中的事件程序正在执行时, T2 thread如何得知并呼叫
: t1.Abort()以中止发生EVENT的THREAD(T1)....
: 感恩您
这... 在 t2 呼叫 t1.Abort() 的时候会产生 ThreadAbortException 啊...
try
{
...
}
catch (ThreadAbortException tae)
{
// thread abort cleanup
}
catch
{
// 正常的 error handling
}
finally
{
// cleanup code
}
在处理完 "finally" block 之後 t1 就会结束了.
即使 t1 正在处理 event, 甚至在event queue还有未处理的 event,
也会按正常出现exception的处理结束掉的.
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 219.73.76.102