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>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>1.0.14</Version>
|
<Version>1.0.15</Version>
|
||||||
<AssemblyVersion>1.0.14.0</AssemblyVersion>
|
<AssemblyVersion>1.0.15.0</AssemblyVersion>
|
||||||
<FileVersion>1.0.14.0</FileVersion>
|
<FileVersion>1.0.15.0</FileVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -30,26 +30,32 @@ public static class CMMCommand
|
|||||||
return ConsoleHelper.CmdCommandAsync($"{CMMexe} /SetValue {monitorSN} D6 4");
|
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;
|
for (int attempt = 0; attempt <= maxRetries; attempt++)
|
||||||
while (reTry <= 5)
|
|
||||||
{
|
{
|
||||||
var cmdFileName = Path.Combine(CMMTmpFolder, $"{Guid.NewGuid()}.bat");
|
var cmdFileName = Path.Combine(CMMTmpFolder, $"{Guid.NewGuid()}.bat");
|
||||||
var cmd = $"{CMMexe} /GetValue {monitorSN} {vcpCode}\r\n" +
|
var cmd = $"{CMMexe} /GetValue {monitorSN} {vcpCode}\r\n" +
|
||||||
$"echo %errorlevel%";
|
$"echo %errorlevel%";
|
||||||
File.WriteAllText(cmdFileName, cmd);
|
File.WriteAllText(cmdFileName, cmd);
|
||||||
var values = await ConsoleHelper.ExecuteCommand(cmdFileName);
|
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;
|
var value = values.Split("\r\n", StringSplitOptions.RemoveEmptyEntries).LastOrDefault();
|
||||||
await Task.Delay(500);
|
|
||||||
await GetMonitorValue(monitorSN, vcpCode, reTry++);
|
|
||||||
};
|
|
||||||
|
|
||||||
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)
|
#region Brightness (VCP Code 10)
|
||||||
|
|||||||
Reference in New Issue
Block a user