Add locking around file save operations
This commit is contained in:
parent
faf97d9659
commit
98c26d0a7c
2 changed files with 11 additions and 4 deletions
|
|
@ -66,6 +66,8 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
|
||||
public static Func<bool> ShouldShowAuthPanel { get; set; }
|
||||
|
||||
private static object writeLock = new object();
|
||||
|
||||
[JsonIgnore]
|
||||
internal PrinterSettingsLayer QualityLayer { get; private set; }
|
||||
|
||||
|
|
@ -204,7 +206,10 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
}
|
||||
}
|
||||
|
||||
File.WriteAllText(DocumentPath, json);
|
||||
lock (writeLock)
|
||||
{
|
||||
File.WriteAllText(DocumentPath, json);
|
||||
}
|
||||
|
||||
if (ActiveSliceSettings.Instance.ID == this.ID)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
|
||||
public const string ProfileExtension = ".printer";
|
||||
|
||||
private static object writeLock = new object();
|
||||
private static EventHandler unregisterEvents;
|
||||
private static readonly string userDataPath = ApplicationDataStorage.ApplicationUserDataPath;
|
||||
private static string ProfilesPath
|
||||
|
|
@ -80,7 +81,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
{
|
||||
get
|
||||
{
|
||||
|
||||
string username = UserSettings.Instance.get("ActiveUserName");
|
||||
|
||||
if (string.IsNullOrEmpty(username))
|
||||
|
|
@ -100,7 +100,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
}
|
||||
return username;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static ProfileManager()
|
||||
|
|
@ -524,7 +523,10 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
|
||||
public void Save()
|
||||
{
|
||||
File.WriteAllText(ProfilesDBPath, JsonConvert.SerializeObject(this, Formatting.Indented));
|
||||
lock(writeLock)
|
||||
{
|
||||
File.WriteAllText(ProfilesDBPath, JsonConvert.SerializeObject(this, Formatting.Indented));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue