Fix retry loop - don't retry on timeout
- 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 <noreply@anthropic.com>
This commit is contained in:
@@ -13,9 +13,9 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<Version>1.0.14</Version>
|
||||
<AssemblyVersion>1.0.14.0</AssemblyVersion>
|
||||
<FileVersion>1.0.14.0</FileVersion>
|
||||
<Version>1.0.15</Version>
|
||||
<AssemblyVersion>1.0.15.0</AssemblyVersion>
|
||||
<FileVersion>1.0.15.0</FileVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -30,26 +30,32 @@ public static class CMMCommand
|
||||
return ConsoleHelper.CmdCommandAsync($"{CMMexe} /SetValue {monitorSN} D6 4");
|
||||
}
|
||||
|
||||
private static async Task<string> GetMonitorValue(string monitorSN, string vcpCode = "D6", int? reTry = 0)
|
||||
private static async Task<string> 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();
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user