简体   繁体   中英

Determine which thread exception occurred in DispatcherUnhandledException

I have a WPF app in which we are using tasks to invoke new threads. I have an App_DispatcherUnhandledException event in the code to catch any areas that occur on any thread, which works fine. For the purposes of logging however I'd like to determine whether the exception occured on main thread or on a task. Is this possible?

The event args object has a Dispatcher property, which has a Thread property:

Dispatcher.UnhandledException Event - http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher.unhandledexception(v=vs.110).aspx

DispatcherUnhandledExceptionFilterEventArgs Class - http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcherunhandledexceptionfiltereventargs(v=vs.110).aspx

DispatcherEventArgs.Dispatcher Property - http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchereventargs.dispatcher(v=vs.110).aspx

You can name threads, or store the managed ID of the main one to identify the thread from that.

Hope that helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM