Reputation: 7621
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?
Upvotes: 0
Views: 103
Reputation: 42003
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!
Upvotes: 2