Fix deadlock when loading new settings

This commit is contained in:
UrbanCMC 2023-08-28 17:28:44 +02:00
parent bdb60f26a7
commit 21bf0a87c9
2 changed files with 4 additions and 4 deletions

View File

@ -5,9 +5,9 @@ public class MainSettings
public const string SettingsFileName = "app_settings";
private const int SettingsVersion = 1;
public int CurrentSettingsVersion { get; private set; }
public int CurrentSettingsVersion { get; set; }
public PerformanceSettings PerformanceSettings { get; } = new();
public PerformanceSettings PerformanceSettings { get; set; } = new();
public bool Upgrade()
{

View File

@ -100,8 +100,8 @@ public static class ServiceExtensions
MainSettings GetAppSettings(IServiceProvider provider, string name)
{
var settingsManager = provider.GetService<SettingsManager>();
var settings = settingsManager!.Load<MainSettings>(name).Result;
var settingsManager = provider.GetRequiredService<SettingsManager>();
var settings = Task.Run(() => settingsManager.Load<MainSettings>(name)).Result;
if (settings.Upgrade())
{
settingsManager.Save(MainSettings.SettingsFileName, settings).FireAndForget();