From e9f0e75d6096e4f62e46433d94d912797d5a57ff Mon Sep 17 00:00:00 2001 From: Dork Normalize <nope> Date: Mon, 31 Mar 2025 04:33:28 -0700 Subject: [PATCH] Drastically increase log processing speed --- AutoTrackR2/LogHandler.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/AutoTrackR2/LogHandler.cs b/AutoTrackR2/LogHandler.cs index 6cb61dd..3c7bef5 100644 --- a/AutoTrackR2/LogHandler.cs +++ b/AutoTrackR2/LogHandler.cs @@ -100,14 +100,20 @@ public class LogHandler(string logPath) { CheckGameProcessState(); - if (_reader?.ReadLine() is { } line) + List<string> lines = new List<string>(); + while (_reader.ReadLine() is { } line) + { + lines.Add(line); + } + + foreach (var line in lines) { // start new thread to handle log entry var thread = new Thread(() => HandleLogEntry(line)); thread.Start(); // Console.WriteLine(line); } - else + { // Wait for new lines to be written to the log file Thread.Sleep(1000); @@ -131,14 +137,8 @@ public class LogHandler(string logPath) _reader?.Close(); _fileStream?.Close(); - // Wait for the log file to be written to - Thread.Sleep(3000); - _fileStream = new FileStream(_logPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); _reader = new StreamReader(_fileStream); - - // Skip all the startup junk - while (_reader.ReadLine() is { } line) { } } _gameProcessState = newGameProcessState;