mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-15 17:30:27 +08:00
chore: 重启函数添加 CallerMemberName,UntilIdleAsync 添加消抖
This commit is contained in:
@@ -377,16 +377,17 @@ namespace MaaWpfGui.Main
|
||||
/// <summary>
|
||||
/// 重启,不带参数
|
||||
/// </summary>
|
||||
public static void ShutdownAndRestartWithoutArgs()
|
||||
/// <param name="caller">Caller Member Name</param>
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
/// <summary>
|
||||
/// 等待状态变为闲置
|
||||
/// </summary>
|
||||
/// <param name="time">查询间隔</param>
|
||||
/// <param name="time">查询间隔(ms)</param>
|
||||
/// <param name="confirmInterval">确认间隔(ms)</param>
|
||||
/// <param name="confirmTimes">确认次数</param>
|
||||
/// <returns>Task</returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user