From 1803f77325c105984c4a7bd40fcce8fffcdee37c Mon Sep 17 00:00:00 2001 From: uye <99072975+ABA2396@users.noreply.github.com> Date: Mon, 26 May 2025 14:38:38 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E9=87=8D=E5=90=AF=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20CallerMemberName=EF=BC=8CUntilIdleAsync=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B6=88=E6=8A=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaWpfGui/Main/Bootstrapper.cs | 7 ++--- src/MaaWpfGui/States/RunningState.cs | 38 +++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/MaaWpfGui/Main/Bootstrapper.cs b/src/MaaWpfGui/Main/Bootstrapper.cs index a43f0df193..c7dff412d7 100644 --- a/src/MaaWpfGui/Main/Bootstrapper.cs +++ b/src/MaaWpfGui/Main/Bootstrapper.cs @@ -377,16 +377,17 @@ namespace MaaWpfGui.Main /// /// 重启,不带参数 /// - public static void ShutdownAndRestartWithoutArgs() + /// Caller Member Name + public static void ShutdownAndRestartWithoutArgs([CallerMemberName] string caller = "") { _isRestartingWithoutArgs = true; - _logger.Information("Shutdown and restart without Args"); + _logger.Information($"Shutdown and restart without Args, call by `{caller}`"); Execute.OnUIThread(Application.Current.Shutdown); } public static void Shutdown([CallerMemberName] string caller = "") { - _logger.Information($"Shutdown called by {caller}"); + _logger.Information($"Shutdown called by `{caller}`"); Execute.OnUIThread(Application.Current.Shutdown); } diff --git a/src/MaaWpfGui/States/RunningState.cs b/src/MaaWpfGui/States/RunningState.cs index c16cd7d093..f370c68d54 100644 --- a/src/MaaWpfGui/States/RunningState.cs +++ b/src/MaaWpfGui/States/RunningState.cs @@ -17,12 +17,15 @@ using MaaWpfGui.Constants; using MaaWpfGui.Helper; using MaaWpfGui.Utilities; using MaaWpfGui.ViewModels.UI; +using Serilog; +using Serilog.Core; namespace MaaWpfGui.States { public class RunningState { private static RunningState _instance; + private static ILogger _logger = Logger.None; private RunningState() { @@ -161,13 +164,40 @@ namespace MaaWpfGui.States /// /// 等待状态变为闲置 /// - /// 查询间隔 + /// 查询间隔(ms) + /// 确认间隔(ms) + /// 确认次数 /// Task - public async Task UntilIdleAsync(int time = 1000) + public async Task UntilIdleAsync(int time = 1000, int confirmInterval = 1000, int confirmTimes = 3) { - while (!GetIdle()) + while (true) { - await Task.Delay(time); + while (!GetIdle()) + { + await Task.Delay(time); + } + + int confirmed = 0; + while (confirmed < confirmTimes) + { + await Task.Delay(confirmInterval); + + if (GetIdle()) + { + confirmed++; + } + else + { + _logger.Information("Idle state changed during confirmation, resetting confirmation count."); + break; + } + } + + if (confirmed >= confirmTimes) + { + _logger.Information($"Idle state confirmed after {confirmTimes} checks."); + return; + } } } }