|
@@ -1,10 +1,7 @@
|
|
|
-using System;
|
|
|
-using System.Collections.Generic;
|
|
|
-using System.Configuration;
|
|
|
-using System.Data;
|
|
|
-using System.Linq;
|
|
|
-using System.Threading.Tasks;
|
|
|
+using AIPlatform.Protocol.Utilities;
|
|
|
+using System;
|
|
|
using System.Windows;
|
|
|
+using System.Windows.Threading;
|
|
|
|
|
|
namespace aipreviewer
|
|
|
{
|
|
@@ -13,5 +10,28 @@ namespace aipreviewer
|
|
|
/// </summary>
|
|
|
public partial class App : Application
|
|
|
{
|
|
|
+ protected override void OnStartup(StartupEventArgs e)
|
|
|
+ {
|
|
|
+ // 添加对AppDomain中未处理异常的处理程序
|
|
|
+ AppDomain.CurrentDomain.UnhandledException += OnDomainOnUnhandledException;
|
|
|
+ // 添加对Dispatcher中未处理异常的处理程序
|
|
|
+ Current.DispatcherUnhandledException += OnDispatcherUnhandledException;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs e)
|
|
|
+ {
|
|
|
+ // 此时不能执行UI操作,因为这不是在UI线程上
|
|
|
+ Exception exception = (Exception)e.ExceptionObject;
|
|
|
+ Logger.WriteLineError($"OnDomainOnUnhandledException: {exception}");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
|
|
|
+ {
|
|
|
+ // 可以在这里执行UI操作,因为这是在UI线程上
|
|
|
+ Exception exception = e.Exception;
|
|
|
+ Logger.WriteLineError($"OnDispatcherUnhandledException: {exception}");
|
|
|
+ MessageBox.Show($"An unexpected error has occurred.\r\n{exception.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ e.Handled = true; // 如果设置为true,则不会关闭应用程序
|
|
|
+ }
|
|
|
}
|
|
|
}
|