Skip to content

Commit

Permalink
Merge pull request #373 from eesast/dev
Browse files Browse the repository at this point in the history
 fix(Logger): 🐛 too many threads in Logger & ensure AddMoneyNaturally
  • Loading branch information
DreamEnderKing authored May 11, 2024
2 parents a061c21 + 3b43b98 commit f9902cf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
5 changes: 4 additions & 1 deletion logic/Gaming/ActionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,10 @@ public bool AddMoneyNaturally(Base team)
(
() =>
{
Thread.Sleep(GameData.CheckInterval);
while (!gameMap.Timer.IsGaming)
{
Thread.Sleep(1);
}
new FrameRateTaskExecutor<int>
(
loopCondition: () => gameMap.Timer.IsGaming,
Expand Down
16 changes: 6 additions & 10 deletions logic/Preparation/Utility/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ public class LogQueue

private readonly Queue<string> 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;
Expand Down Expand Up @@ -79,7 +76,6 @@ private LogQueue()
).Start();
})
{ IsBackground = true }.Start();
var t = new Thread(() => { });
}
}

Expand All @@ -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)
Expand All @@ -109,22 +105,22 @@ public void ConsoleLogDebug(string msg, bool Duplicate = true)
if (!Background)
Console.WriteLine(info);
if (Duplicate)
_ = LogQueue.Global.Commit(info);
LogQueue.Global.Commit(info);
}
#endif
}
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
}

Expand Down

0 comments on commit f9902cf

Please sign in to comment.