[英]How to handle an exception globally while make sure the app won't exit?
這是一個EntityException,當EntityFramework無法聯系Sql數據庫,但僅關閉數據庫時,該應用程序的其余部分仍然可以正常工作。 那么,有辦法嗎? 我嘗試使用AppDomain.CurrentDomain.UnhandledException
但該應用程序仍以發布模式退出。 謝謝!
我相信您正在尋找這個:
public partial class App
{
public App()
{
this.Dispatcher.UnhandledException += OnDispatcherUnhandledException;
}
private async void OnDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
await ErrorService.HandleError(e.Exception, "An unhandled exception occurred", true, true);
e.Handled = true;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.