From bd7a58a5fed2c5e07b7b9939461049e500e95e50 Mon Sep 17 00:00:00 2001 From: Dave Friedel Date: Wed, 7 Jan 2026 12:01:47 -0500 Subject: [PATCH] Fix retry loop - don't retry on timeout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fixed buggy recursive retry logic - Reduced max retries from 5 to 2 - Don't retry if timeout occurred (empty result) - Monitor is unresponsive, retrying just wastes time 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- DellMonitorControl/DellMonitorControl.csproj | 6 ++--- Library/Method/CMMCommand.cs | 26 ++++++++++++-------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/DellMonitorControl/DellMonitorControl.csproj b/DellMonitorControl/DellMonitorControl.csproj index dcb574b..2aac306 100644 --- a/DellMonitorControl/DellMonitorControl.csproj +++ b/DellMonitorControl/DellMonitorControl.csproj @@ -13,9 +13,9 @@ - 1.0.14 - 1.0.14.0 - 1.0.14.0 + 1.0.15 + 1.0.15.0 + 1.0.15.0 diff --git a/Library/Method/CMMCommand.cs b/Library/Method/CMMCommand.cs index 7ebcdee..cabf4e1 100644 --- a/Library/Method/CMMCommand.cs +++ b/Library/Method/CMMCommand.cs @@ -30,26 +30,32 @@ public static class CMMCommand return ConsoleHelper.CmdCommandAsync($"{CMMexe} /SetValue {monitorSN} D6 4"); } - private static async Task GetMonitorValue(string monitorSN, string vcpCode = "D6", int? reTry = 0) + private static async Task GetMonitorValue(string monitorSN, string vcpCode = "D6", int maxRetries = 2) { - var value = string.Empty; - while (reTry <= 5) + for (int attempt = 0; attempt <= maxRetries; attempt++) { var cmdFileName = Path.Combine(CMMTmpFolder, $"{Guid.NewGuid()}.bat"); var cmd = $"{CMMexe} /GetValue {monitorSN} {vcpCode}\r\n" + $"echo %errorlevel%"; File.WriteAllText(cmdFileName, cmd); var values = await ConsoleHelper.ExecuteCommand(cmdFileName); - File.Delete(cmdFileName); + try { File.Delete(cmdFileName); } catch { } - value = values.Split("\r\n", StringSplitOptions.RemoveEmptyEntries).LastOrDefault(); + // Empty result means timeout - don't retry, monitor is unresponsive + if (string.IsNullOrEmpty(values)) + return string.Empty; - if (!string.IsNullOrEmpty(value) && value != "0") return value; - await Task.Delay(500); - await GetMonitorValue(monitorSN, vcpCode, reTry++); - }; + var value = values.Split("\r\n", StringSplitOptions.RemoveEmptyEntries).LastOrDefault(); - return value; + if (!string.IsNullOrEmpty(value) && value != "0") + return value; + + // Only retry on non-timeout failures + if (attempt < maxRetries) + await Task.Delay(300); + } + + return string.Empty; } #region Brightness (VCP Code 10)