简体   繁体   English

如何处理WPF应用程序中未处理的应用程序级异常?

[英]How do I handle unhandled Application level exceptions in a WPF application?

I'm migrating an existing Winforms based application to WPF. 我正在将现有的基于Winforms的应用程序迁移到WPF。

For handling unhandled exceptions at the application level in my Winforms app, I did the following: 为了在Winforms应用程序中处理应用程序级别的未处理异常,我做了以下工作:

Application.ThreadException
    += new ThreadExceptionEventHandler(Application_ThreadException);     

AppDomain.CurrentDomain.UnhandledException
    += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);   

Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

How do I go about handling these conditions in a WPF based application? 如何在基于WPF的应用程序中处理这些条件?

您可以处理Application的当前实例的事件DispatcherUnhandledException

Application.Current.DispatcherUnhandledException += (s,e) => {...};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在控制台应用程序中捕获未处理的异常 - How to catching Unhandled Exceptions in Console application 如何处理这些异常,以便在没有连接时我的应用程序不会崩溃? - How do I handle these exceptions so that my application doesn't crash when there is no connection? 如何在 WinForms 应用程序中创建一些可以捕获所有“未处理”异常的东西? - How can I make something that catches all 'unhandled' exceptions in a WinForms application? How do I create a WPF application that can handle the URL:callto and URL:tel protocols in Windows 10? - How do I create a WPF application that can handle the URL:callto and URL:tel protocols in Windows 10? 如何正确捕获 WinForms 应用程序中所有未处理的异常 - How to catch all unhandled exceptions in WinForms application correctly 如何以编程方式退出 WPF 应用程序? - How do I exit a WPF application programmatically? 如何在WPF应用程序中处理图像内存? - How can I handle image memory in a WPF application? WPF中的应用程序级变量 - Application level variable in WPF 如何有条件地禁止写入事件日志的应用程序异常? - How do I conditionally suppress application exceptions written to the event log? 如果发生未处理的异常,我需要关闭WPF应用程序吗? - If unhandled exception happens I need to shutdown the WPF Application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM