zoukankan      html  css  js  c++  java
  • 解决WPF中异常导致的程序Crash

    通常在WPF中出现异常,会导致程序Crash,即使把异常Throw出来,依旧会报错,解决方法只需在App.xaml.cs中进行处理即可,废话不说,代码如下:

    private int exceptionCount;

    private void Application_Startup(object sender, StartupEventArgs e)
    {
    AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
    Current.DispatcherUnhandledException += Application_DispatcherUnhandledException;
    }

    private void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
    {
    //"I'm sorry, the current application occured some issues.." +
    if (exceptionCount > 0) { exceptionCount = 0; e.Handled = true; return; }
    MessageWindow.Show(MessageLevel.Error, e.Exception.Message);
    exceptionCount++;
    e.Handled = true;
    }

    private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
    {
    Exception ex = e.ExceptionObject as Exception;
    MessageWindow.Show(MessageLevel.Error, ResourceHelper.GetRsByKey("LOC_Error_00002") + e.ExceptionObject);
    }

  • 相关阅读:
    Thread
    投资
    DBLink
    sql
    列转行
    DataTable,DataView,DataRowView,DefaultView与DataSet
    Vue.js 基础学习之组件
    Vue.js 基础学习计算属性computed
    v-model的修饰符和使用
    Vue.js 基础学习 v-on 指令
  • 原文地址:https://www.cnblogs.com/zunzunQ/p/6729685.html
Copyright © 2011-2022 走看看