From f47a27a7debf17dcd3af6722349d3ceda45f30fc Mon Sep 17 00:00:00 2001 From: N00MKRAD <61149547+n00mkrad@users.noreply.github.com> Date: Sat, 28 Sep 2024 22:20:13 +0200 Subject: [PATCH] Allow retrying when writing config json --- CodeLegacy/IO/Config.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/CodeLegacy/IO/Config.cs b/CodeLegacy/IO/Config.cs index a56188f..82fad42 100644 --- a/CodeLegacy/IO/Config.cs +++ b/CodeLegacy/IO/Config.cs @@ -72,7 +72,21 @@ namespace Flowframes.IO return; SortedDictionary cachedValuesSorted = new SortedDictionary(CachedValues); - File.WriteAllText(configPath, JsonConvert.SerializeObject(cachedValuesSorted, Formatting.Indented)); + + // Retry every 100ms up to 10 times in case of an exception + for (int i = 0; i < 10; i++) + { + try + { + File.WriteAllText(configPath, JsonConvert.SerializeObject(cachedValuesSorted, Formatting.Indented)); + return; + } + catch (Exception e) + { + Logger.Log($"Failed to write config{(i < 10 ? ", will retry." : " and out of retries!")} {e.Message}", true); + Task.Delay(100).Wait(); + } + } } private static void Reload()