使用ThreadExceptionEventHandler:确定哪个线程导致异常 [英] Using ThreadExceptionEventHandler: determine which thread caused the exception
问题描述
使用Application.ThreadExceptionEventHandler,是有可能确定哪个线程导致异常(线程ID)?
Using the Application.ThreadExceptionEventHandler, is it possible to determine which thread caused the exception (the thread id)?
同样的问题适用于使用AppDomain.UnhandledExceptionEventHandler赶上非UI线程例外。
The same question applies to using the AppDomain.UnhandledExceptionEventHandler to catch non-UI thread exceptions.
如果答案是否定的,有没有其他的方法来确定哪个线程在这种情况下提出的未处理的异常?
If the answer is no, is there any other way to determine which thread raised the unhandled exception in such cases?
推荐答案
我还没有签,但是我希望在处理程序中引发异常的线程中执行 - 在这种情况下 Thread.CurrentThread
将是你想要的。我看不出它是如何多大意义的处理程序在任何的等的线程中执行。
I haven't checked, but I'd expect the handler to be executed in the thread which threw the exception - in which case Thread.CurrentThread
would be what you want. I can't see how it would make much sense for the handler to be executed in any other thread.
这篇关于使用ThreadExceptionEventHandler:确定哪个线程导致异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!