wpf 捕获全局异常
App()
{
this.Startup += App_Startup;
}
private void App_Startup(object sender, StartupEventArgs e)
{
this.DispatcherUnhandledException += App_DispatcherUnhandledException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
}
//主线程未处理异常
private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
//HandyControl.Controls.Growl.Error($"应用程序遇到未处理的异常:{e.Exception.Message}");
e.Handled = true;
}
//未处理线程异常(如果主线程未处理异常已经处理,该异常不会触发)
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
if (e.ExceptionObject is Exception ex)
{
//HandyControl.Controls.Growl.Error($"应用程序遇到未处理的异常:{ex.Message}");
}
}
//未处理的Task内异常
private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
//HandyControl.Controls.Growl.Error($"应用程序遇到未处理的异常:{e.Exception.Message}");
}
留待后查,同时方便他人
联系我:renhanlinbsl@163.com
联系我:renhanlinbsl@163.com
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2018-05-29 windows下linux子系统安装
2018-05-29 mongoDB学习记录