WPF-用于捕获未知异常导致的系统崩溃

public App()
        {
            Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
        }

        void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            MessageBox.Show("UI系统出现异常,请联系管理员.", "UI意外的操作", MessageBoxButton.OK, MessageBoxImage.Information);
        }


        void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            MessageBox.Show(e.Exception.Message);
            MessageBox.Show("Code系统出现异常,请联系管理员.", "Code意外的操作", MessageBoxButton.OK, MessageBoxImage.Information);
            e.Handled = true;//使用这一行代码告诉运行时,该异常被处理了,不再作为UnhandledException抛出了。
        }

 

posted @ 2015-12-28 17:22  倾国倾城何为倾  阅读(407)  评论(0编辑  收藏  举报