Skip to content

Commit abf23fd

Browse files
committed
retry 5 times if config write fails
1 parent b84db2e commit abf23fd

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

ff-utils-winforms/IO/Config.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,21 @@ public static void Set(Dictionary<string, string> keyValuePairs)
7171
WriteConfig();
7272
}
7373

74-
private static void WriteConfig()
74+
private static async Task WriteConfig(int tries = 5)
7575
{
76-
SortedDictionary<string, string> cachedValuesSorted = new SortedDictionary<string, string>(cachedValues);
77-
File.WriteAllText(configPath, JsonConvert.SerializeObject(cachedValuesSorted, Formatting.Indented));
76+
try
77+
{
78+
File.WriteAllText(configPath, JsonConvert.SerializeObject(new SortedDictionary<string, string>(cachedValues), Formatting.Indented));
79+
}
80+
catch
81+
{
82+
if (tries > 0)
83+
{
84+
Logger.Log($"Failed to write config. Retrying ({tries} tries left)", true);
85+
await Task.Delay(200);
86+
await WriteConfig(tries - 1);
87+
}
88+
}
7889
}
7990

8091
private static void Reload()

0 commit comments

Comments
 (0)