In my software I have a thread
that every second updates the file X. This same file can also be updated through a user action that will be in another thread
(can be any time).
My question is: what will happen if both threads
tries to save the X file at the exact same time? Is there a way to ensure that the file is updated in both cases?
I need to ensure that the file is updated in both cases. Failing to update the file is not an option.
I know it can be very rare to happen (in the exact thousandth of a second) two threads
try to save the same file at the same time. But what if it does?
I'm currently using the code below to save the files:
using (var streamWriter = new StreamWriter(filename, false))
{
streamWriter.WriteLine(encrypted);
}