Original: WPF exception captures three processing UI threads, global exceptions, task exceptions
protected override void Onstartup (StartupEventArgs e)
{
Base. Onstartup (e);
Registerevents ();
}
private void Registerevents ()
{
Taskscheduler.unobservedtaskexception + = (sender, args) =
//{
MessageBox.Show (args. Exception.Message);
Args. Setobserved ();
//};
This. Dispatcherunhandledexception + = app_dispatcherunhandledexception;
Taskscheduler.unobservedtaskexception + = new eventhandler<
Unobservedtaskexceptioneventargs> (taskscheduler_unobservedtaskexception);
AppDomain.CurrentDomain.UnhandledException + = currentdomain_unhandledexception;
}
private void App_dispatcherunhandledexception (object sender, Dispatcherunhandledexceptioneventargs e)
{
}
static void Taskscheduler_unobservedtaskexception (object sender, Unobservedtaskexceptioneventargs e)
{
foreach (Exception item in e.exception.innerexceptions)
{
Console.WriteLine ("Exception type: {0}{1} from: {2}{3} exception content: {4}",
Item. GetType (), Environment.NewLine, item. Source,
Environment.NewLine, item. Message);
}
Identifies the exception as having been observed
E.setobserved ();
}
private void Currentdomain_unhandledexception (object sender, UnhandledExceptionEventArgs e)
{
MessageBox.Show ("Unhandled exception.");
}
WPF exception capture three handles UI thread, global exception, task exception