From f534c5a269d0c21320c98609324d8684ecde1b8e Mon Sep 17 00:00:00 2001 From: 964293341 Date: Sun, 12 May 2024 00:37:51 +0800 Subject: [PATCH 1/2] fix(Logger): :bug: too many threads in `Logger` --- logic/Preparation/Utility/Logger.cs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/logic/Preparation/Utility/Logger.cs b/logic/Preparation/Utility/Logger.cs index b41006c4..93a14402 100755 --- a/logic/Preparation/Utility/Logger.cs +++ b/logic/Preparation/Utility/Logger.cs @@ -16,12 +16,9 @@ public class LogQueue private readonly Queue logInfoQueue = new(); - public async Task Commit(string info) + public void Commit(string info) { - await Task.Run(() => - { - lock (queueLock) logInfoQueue.Enqueue(info); - }); + lock (queueLock) logInfoQueue.Enqueue(info); } public static bool IsClosed { get; private set; } = false; @@ -79,7 +76,6 @@ private LogQueue() ).Start(); }) { IsBackground = true }.Start(); - var t = new Thread(() => { }); } } @@ -97,7 +93,7 @@ public void ConsoleLog(string msg, bool Duplicate = true) if (!Background) Console.WriteLine(info); if (Duplicate) - _ = LogQueue.Global.Commit(info); + LogQueue.Global.Commit(info); } } public void ConsoleLogDebug(string msg, bool Duplicate = true) @@ -109,7 +105,7 @@ public void ConsoleLogDebug(string msg, bool Duplicate = true) if (!Background) Console.WriteLine(info); if (Duplicate) - _ = LogQueue.Global.Commit(info); + LogQueue.Global.Commit(info); } #endif } @@ -117,14 +113,14 @@ public static void RawConsoleLog(string msg, bool Duplicate = true) { Console.WriteLine(msg); if (Duplicate) - _ = LogQueue.Global.Commit(msg); + LogQueue.Global.Commit(msg); } public static void RawConsoleLogDebug(string msg, bool Duplicate = true) { #if DEBUG Console.WriteLine(msg); if (Duplicate) - _ = LogQueue.Global.Commit(msg); + LogQueue.Global.Commit(msg); #endif } From aaf8a6b7e907db748446e6691417568ed1794267 Mon Sep 17 00:00:00 2001 From: 964293341 Date: Sun, 12 May 2024 01:35:59 +0800 Subject: [PATCH 2/2] fix(ActionManager): :bug: ensure `AddMoneyNaturally` frt start normally --- logic/Gaming/ActionManager.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/logic/Gaming/ActionManager.cs b/logic/Gaming/ActionManager.cs index 37c3d021..8c7cf996 100755 --- a/logic/Gaming/ActionManager.cs +++ b/logic/Gaming/ActionManager.cs @@ -301,7 +301,10 @@ public bool AddMoneyNaturally(Base team) ( () => { - Thread.Sleep(GameData.CheckInterval); + while (!gameMap.Timer.IsGaming) + { + Thread.Sleep(1); + } new FrameRateTaskExecutor ( loopCondition: () => gameMap.Timer.IsGaming,