Skip to content

Commit 3b43b98

Browse files
Merge pull request #371 from asdawej/patch
fix(Logger): 🐛 too many threads in `Logger` & ensure `AddMoneyNaturally`
2 parents 5b56b9d + 68619aa commit 3b43b98

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

logic/Gaming/ActionManager.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,10 @@ public bool AddMoneyNaturally(Base team)
301301
(
302302
() =>
303303
{
304-
Thread.Sleep(GameData.CheckInterval);
304+
while (!gameMap.Timer.IsGaming)
305+
{
306+
Thread.Sleep(1);
307+
}
305308
new FrameRateTaskExecutor<int>
306309
(
307310
loopCondition: () => gameMap.Timer.IsGaming,

logic/Preparation/Utility/Logger.cs

+6-10
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@ public class LogQueue
1616

1717
private readonly Queue<string> logInfoQueue = new();
1818

19-
public async Task Commit(string info)
19+
public void Commit(string info)
2020
{
21-
await Task.Run(() =>
22-
{
23-
lock (queueLock) logInfoQueue.Enqueue(info);
24-
});
21+
lock (queueLock) logInfoQueue.Enqueue(info);
2522
}
2623

2724
public static bool IsClosed { get; private set; } = false;
@@ -79,7 +76,6 @@ private LogQueue()
7976
).Start();
8077
})
8178
{ IsBackground = true }.Start();
82-
var t = new Thread(() => { });
8379
}
8480
}
8581

@@ -97,7 +93,7 @@ public void ConsoleLog(string msg, bool Duplicate = true)
9793
if (!Background)
9894
Console.WriteLine(info);
9995
if (Duplicate)
100-
_ = LogQueue.Global.Commit(info);
96+
LogQueue.Global.Commit(info);
10197
}
10298
}
10399
public void ConsoleLogDebug(string msg, bool Duplicate = true)
@@ -109,22 +105,22 @@ public void ConsoleLogDebug(string msg, bool Duplicate = true)
109105
if (!Background)
110106
Console.WriteLine(info);
111107
if (Duplicate)
112-
_ = LogQueue.Global.Commit(info);
108+
LogQueue.Global.Commit(info);
113109
}
114110
#endif
115111
}
116112
public static void RawConsoleLog(string msg, bool Duplicate = true)
117113
{
118114
Console.WriteLine(msg);
119115
if (Duplicate)
120-
_ = LogQueue.Global.Commit(msg);
116+
LogQueue.Global.Commit(msg);
121117
}
122118
public static void RawConsoleLogDebug(string msg, bool Duplicate = true)
123119
{
124120
#if DEBUG
125121
Console.WriteLine(msg);
126122
if (Duplicate)
127-
_ = LogQueue.Global.Commit(msg);
123+
LogQueue.Global.Commit(msg);
128124
#endif
129125
}
130126

0 commit comments

Comments
 (0)