I need to show settings form for the user, save results to config file and always use the latest settings inside background thread of the main form.
What is the best way to avoid situations like race condition in this case (reading and writing to the config file simultaneously)? What is the best practice to do it in C# and Windows Forms?
To be more precise, I have global hotkey that opens settings form like this:
var settingsForm = new SettingsForm();
settingsForm.Show();
On this settings form I have two buttons -- "Ok" and "Cancel". When the user presses "Ok" button, new settings writing to config file.
In the main form I have a background thread with the infinite loop that do some stuff with the current settings.
Thanks in advance.