c# - C# .net core 3.1 WPF 无异常关闭
问题描述
我的应用程序 WPF .net core 3.1 在 win10 home 中运行了大约两三天,它被关闭并且没有发现任何异常。我在应用程序中放置了异常处理程序
void App_Startup(object sender, StartupEventArgs e)
{
Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
}
private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
string error = "An unhandled exception just occured: " + e.Exception.Message +
Environment.NewLine + "WHERE: " + e.Exception.StackTrace;
string title = "DispatcherUnhandledException";
Log.Logger.Fatal(e.Exception, "Current_DispatcherUnhandledException");
MessageBox.Show(error, title, MessageBoxButton.OK, MessageBoxImage.Warning);
e.Handled = true;
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var ex = e.ExceptionObject as Exception;
string error = "An unhandled exception just occured and application will be exit: " + ex.Message +
Environment.NewLine + "WHERE: " + ex.StackTrace;
string title = "UnhandledException";
Log.Logger.Fatal(ex, "CurrentDomain_UnhandledException");
MessageBox.Show(error, title, MessageBoxButton.OK, MessageBoxImage.Warning);
}
解决方案
推荐阅读
- delphi - 从 Delphi 中提取 TWebBrowser 中的 iframe 内容
- python - 如何以正确的方式为独立的 python 应用程序制作 setup.py?
- jquery - 主页活动类无法删除
- python-3.x - ZMQ 错误:zmq.error.ZMQError:权限被拒绝
- c# - 将 TextBox 中的 id 数量增加一
- python - Django 选择字段
- python - 如何在 python3 中定义这些哈希函数?
- javascript - 如何在 JS 中按字母顺序对 HTML 标签进行排序?
- sql-server - SSIS如何使用作业运行.net core Action
- python - 如何正确使用 Cross Entropy Loss vs Softmax 进行分类?