From 6643405f6a68257dc4dbb4fa161138e899d75c97 Mon Sep 17 00:00:00 2001 From: Lannamokia Date: Fri, 8 Aug 2025 15:45:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=BB=B6=E8=BF=9F?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E5=8A=9F=E8=83=BD=E5=B9=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=BC=80=E6=9C=BA=E8=87=AA=E5=90=AF=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改开机自启注册逻辑为每次启动时检查更新 添加 StartMainProcessWithDelay 方法实现10秒延迟启动 --- MainWindow.xaml.cs | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 48d2f1c..62a0dc0 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -20,14 +20,11 @@ namespace VHDMounter vhdManager.StatusChanged += OnStatusChanged; vhdManager.VHDFilesFound += OnVHDFilesFound; - // 注册开机启动 - if (!StartupManager.IsRegisteredForStartup()) - { - StartupManager.RegisterForStartup(); - } + // 每次启动时检查并更新开机自启注册状态 + StartupManager.RegisterForStartup(); - // 开始主流程 - _ = StartMainProcess(); + // 开始主流程(包含延迟启动) + _ = StartMainProcessWithDelay(); } private void OnStatusChanged(string status) @@ -47,6 +44,29 @@ namespace VHDMounter }); } + private async Task StartMainProcessWithDelay() + { + try + { + // 开机延迟10秒启动 + OnStatusChanged("程序启动中,等待10秒..."); + for (int i = 10; i > 0; i--) + { + OnStatusChanged($"程序启动中,等待{i}秒..."); + await Task.Delay(1000); + } + + OnStatusChanged("延迟完成,开始主流程..."); + await StartMainProcess(); + } + catch (Exception ex) + { + OnStatusChanged($"延迟启动过程中发生错误: {ex.Message}"); + await Task.Delay(5000); + Application.Current.Shutdown(); + } + } + private async Task StartMainProcess() { try