因为工作中需要在多线程中使用事件,本来想在事件中抛出一个异常到主程序中,结果可想而知,失败了。于是作了如下的一个测试,看看多线程中的异常处理问题,代码如下:














































































































代码的执行结果如下:
Begin
Thread Started
root: Cycle Print
child(er0): Enter Thread:child
(er0): Enter Thread:child
root: Cycle Print
child(er0): 0
(er0): 0
(er0): 1
child(er0): 1
root: Cycle Print
(er0): 2
child(er0): 2
(er0): 3
child(er0): 3
(er0): 4
child(er0): 4
(er0): 5
child(er0): 5
(er0): 6
child(er0): 6
root: Cycle Print
(er0): 7
child(er0): 7
(er0): 8
child(er0): 8
(er0): Exit Thread:child
child(er0): Exit Thread:child
root: Cycle Print
root: Cycle Print
root: Cycle Print
root: Cycle Print
root: Cycle Print
root: Cycle Print
Ok
Press Enter to Exit ...
从结果分析,发现如果在线程中发生同步事件,则事件的发生源在同一个线程中,如果线程中发生异步事件,则该事件既不在主线程中,也不再子线程中,而是在系统的临时线程中。
但是这里有一个问题,我无法区分线程的真正不同,哪里可以取得线程号阿?谁能告诉我,这样有线程号的区别,这个例子可以更清楚一些。