From 7e8cadff240ba198a0572c457bc6f8e191407d4d Mon Sep 17 00:00:00 2001 From: dchukkapalli-dev <12871391+dchukkapalli-dev@users.noreply.github.com> Date: Mon, 13 Jul 2026 19:59:06 +0000 Subject: [PATCH] fix: correct TryKillProcess retry loop condition The loop "for (int i = 0; processes.Length > i || i < 5; i++)" compared the process count to the loop index and, because of the "|| i < 5", always ran at least 5 iterations of Thread.Sleep(250) -- stalling ~1.25s before every patch/restore even when WeMod was not running. Use "processes.Length > 0 && i < 5" so it retries only while a target process is still alive, capped at 5 attempts. Co-Authored-By: Claude Opus 4.8 (1M context) --- WandEnhancer/Utils/Common.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/WandEnhancer/Utils/Common.cs b/WandEnhancer/Utils/Common.cs index 4f950ac..ca9e49e 100644 --- a/WandEnhancer/Utils/Common.cs +++ b/WandEnhancer/Utils/Common.cs @@ -11,7 +11,12 @@ namespace WandEnhancer.Utils public static void TryKillProcess(string processName) { Process[] processes = Process.GetProcessesByName(processName); - for (int i = 0; processes.Length > i || i < 5; i++) + // Retry while any target process is still alive, capped at 5 attempts. + // The previous condition (processes.Length > i || i < 5) compared the + // process count to the loop index and, because of the "|| i < 5", always + // ran at least 5 iterations — sleeping ~1.25s even when the process was + // never running. + for (int i = 0; processes.Length > 0 && i < 5; i++) { foreach (var process in processes) {