更新
This commit is contained in:
11
App.xaml.cs
11
App.xaml.cs
@@ -28,6 +28,12 @@ namespace 自救器呼吸器综合检验仪
|
||||
|
||||
private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
|
||||
{
|
||||
if (AppShutdownCoordinator.ShouldSuppressDuringShutdown(e.Exception))
|
||||
{
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
LogError(e.Exception, "UI线程异常");
|
||||
e.Handled = true; // 标记为已处理,避免崩溃(仅用于调试)
|
||||
}
|
||||
@@ -49,6 +55,11 @@ namespace 自救器呼吸器综合检验仪
|
||||
string logPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "error.log");
|
||||
string logContent = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] {type}:\n{ex.ToString()}\n\n";
|
||||
File.AppendAllText(logPath, logContent);
|
||||
if (AppShutdownCoordinator.IsShutdownInProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MessageBox.Show($"发生错误,详情已记录到 {logPath}", "错误");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user