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)