Mega Code Archive
Manage unhandled exceptions that are thrown on secondary user interface (UI) threads
//File:Window.xaml.cs
using System;
using System.Text;
using System.Windows;
using System.Windows.Threading;
namespace WpfApplication1
{
public partial class App : Application
{
void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("{0}\n", e.Exception.InnerException.Message);
sb.AppendFormat("{0}\n", e.Exception.Message);
sb.AppendFormat("Exception handled on main UI thread {0}.", e.Dispatcher.Thread.ManagedThreadId);
MessageBox.Show(sb.ToString());
e.Handled = true;
}
}
}