看板 C_Sharp 關於我們 聯絡資訊
※ 引述《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