From 20db9fc3eb09245844db3b917d08ec849a7684a4 Mon Sep 17 00:00:00 2001 From: "LAPTOP-SA27O0CB\\guoke" Date: Tue, 30 Sep 2025 14:37:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.xaml.cs | 12 ++++++++---- MainWindow.xaml.cs | 11 +---------- Services/EventService.cs | 4 +--- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/App.xaml.cs b/App.xaml.cs index 0a48500..8861b7c 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -35,7 +35,7 @@ namespace WpfApp base.OnStartup(e); // 创建互斥锁,确保应用程序只能启动一个实例 bool createdNew; - _mutex = new Mutex(true, "WinFormsAppSingleInstanceMutex", out createdNew); + _mutex = new Mutex(true, "WpfAppSingleInstanceMutex", out createdNew); // 配置依赖注入 ServiceProvider = ServiceConfiguration.ConfigureServices(); // 初始化日志服务(从依赖注入容器中获取实例,这会触发构造函数并初始化LogService.Log) @@ -46,24 +46,28 @@ namespace WpfApp if (!createdNew) { MessageBox.Show("应用程序已经在运行中,不能重复启动!", "提示", MessageBoxButton.OK, MessageBoxImage.Information); - return; // 退出应用程序 + Shutdown(); // 退出应用程序 + return; } if (!HslCommunication.Authorization.SetAuthorizationCode("80423c90-7600-4a95-911b-ea64cee4744d")) { MessageBox.Show("应用程序内部组件错误无法启动!", "警告", MessageBoxButton.OK, MessageBoxImage.Warning); - return; // 退出应用程序 + Shutdown(); // 退出应用程序 + return; } //绑定主板或cpu 改变了主板或cpu的序列号退出程序 if (!CheckHardwareBinding()) { MessageBox.Show("检测到硬件环境发生变化,应用程序无法启动!", "警告", MessageBoxButton.OK, MessageBoxImage.Warning); LogService.Log.Info($"硬件环境序列号:{HardwareInfo.GetHardwareId()}"); - return; // 退出应用程序 + Shutdown(); // 退出应用程序 + return; } if (DateTime.Now >= new DateTime(2028, 6, 19)) { MessageBox.Show("错误:程序运行环境崩溃,请重新部署软件环境", "警告", MessageBoxButton.OK, MessageBoxImage.Warning); + Shutdown(); // 退出应用程序 return; } diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 61cdfe6..a795a32 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -1,15 +1,6 @@ -using System.Text; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; using guoke; using SqlSugar; +using System.Windows; namespace WpfApp { diff --git a/Services/EventService.cs b/Services/EventService.cs index 3da7cb5..27931ad 100644 --- a/Services/EventService.cs +++ b/Services/EventService.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Concurrent; -using System.Threading.Tasks; +using System.Collections.Concurrent; namespace guoke {