Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Logger): 🐛 too many threads in Logger & ensure AddMoneyNaturally #373

Merged
merged 5 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading