修改App类的App构造函数 

public partial class App : Application
    {
            public App()
            {
                this.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(Application_DispatcherUnhandledException);
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            }

            void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
            {
                try
                {
                    Exception ex = e.ExceptionObject as Exception;
                    string errorMsg = "非WPF窗体线程异常 : \n\n";
                    MessageBox.Show(errorMsg + ex.Message + Environment.NewLine + ex.StackTrace);
                }
                catch
                {
                    MessageBox.Show("不可恢复的WPF窗体线程异常,应用程序将退出!");
                }
            }

            private void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
            {
                try
                {
                    Exception ex = e.Exception;
                    string errorMsg = "WPF窗体线程异常 : \n\n";
                    MessageBox.Show(errorMsg + ex.Message + Environment.NewLine + ex.StackTrace);
                }
                catch
                {
                    MessageBox.Show("不可恢复的WPF窗体线程异常,应用程序将退出!");
                }
            }

        }