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; + } } } }