From 74ddab2abd8d303a2fd80659cb658bf590ba83b2 Mon Sep 17 00:00:00 2001 From: Tyrone CT Date: Mon, 5 Jan 2026 21:27:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CapMachine.Wpf/App.xaml.cs | 17 ++++++++++------ CapMachine.Wpf/Views/MainView.xaml | 2 +- CapMachine.Wpf/Views/MainView.xaml.cs | 28 +++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/CapMachine.Wpf/App.xaml.cs b/CapMachine.Wpf/App.xaml.cs index c5b0261..f9f643f 100644 --- a/CapMachine.Wpf/App.xaml.cs +++ b/CapMachine.Wpf/App.xaml.cs @@ -316,7 +316,7 @@ namespace CapMachine.Wpf void App_Exit(object sender, ExitEventArgs e) { //程序退出时需要处理的业务 - LogService.Error("程序退出"); + LogService.Error($"程序退出:{e.ToString()}"); } @@ -331,12 +331,14 @@ namespace CapMachine.Wpf try { HandleException(e.Exception); - MessageBox.Show("UI线程异常:" + e.Exception.Message); + //MessageBox.Show("UI线程异常:" + e.Exception.Message); + LogService.Error("UI线程异常:" + e.Exception.Message); } catch (Exception ex) { HandleException(ex); - MessageBox.Show("UI线程发生致命错误!"); + //MessageBox.Show("UI线程发生致命错误!"); + LogService.Error("UI线程发生致命错误!"); } finally { @@ -373,12 +375,14 @@ namespace CapMachine.Wpf { sbEx.Append(e.ExceptionObject); } - MessageBox.Show(sbEx.ToString()); - + LogService.Error(sbEx.ToString()); + //MessageBox.Show(sbEx.ToString()); + } } catch (Exception ex) { + LogService.Error(ex.ToString()); HandleException(ex); } finally @@ -401,7 +405,8 @@ namespace CapMachine.Wpf { HandleException(exception); //task线程内未处理捕获 - MessageBox.Show("Task线程异常:" + e.Exception.Message); + LogService.Error($"Task线程异常" + e.Exception.Message); + //MessageBox.Show("Task线程异常:" + e.Exception.Message); } } catch (Exception ex) diff --git a/CapMachine.Wpf/Views/MainView.xaml b/CapMachine.Wpf/Views/MainView.xaml index 8764f44..898d90c 100644 --- a/CapMachine.Wpf/Views/MainView.xaml +++ b/CapMachine.Wpf/Views/MainView.xaml @@ -19,7 +19,7 @@ WindowStartupLocation="CenterScreen" WindowState="Maximized" WindowStyle="SingleBorderWindow" - mc:Ignorable="d"> + mc:Ignorable="d" Closing="Window_Closing" Closed="Window_Closed"> diff --git a/CapMachine.Wpf/Views/MainView.xaml.cs b/CapMachine.Wpf/Views/MainView.xaml.cs index 63e76e7..dd4dc56 100644 --- a/CapMachine.Wpf/Views/MainView.xaml.cs +++ b/CapMachine.Wpf/Views/MainView.xaml.cs @@ -26,6 +26,34 @@ namespace CapMachine.Wpf.Views LogService.Info($"Windows状态:{this.WindowState}-Visibility: {this.Visibility}"); } + /// + /// 主界面正要关闭 + /// + /// + /// + private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) + { + // 弹窗提示是否确定要退出 + MessageBoxResult result = MessageBox.Show("您确定要退出程序吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.None, MessageBoxResult.Cancel); + //System.Console.WriteLine(result); + if (result == MessageBoxResult.Cancel) + { + e.Cancel = true; // 中断点击事件 + } + else + { + LogService.Info("Windows关闭"); + } + } + /// + /// 主界面完成关闭 + /// + /// + /// + private void Window_Closed(object sender, EventArgs e) + { + Environment.Exit(0); // 强制结束 + } } } \ No newline at end of file