I need to work with a single file (read and write) from DIFFERENT processes. Since there is a competition between processes, it is necessary to block the file. Currently recording is implemented as follows:
const int MAX_RETRY = 50;
const int DELAY_MS = 200;
bool Success = false;
int Retry = 0;
while (!Success && Retry < MAX_RETRY)
{
try
{
using (StreamWriter Wr = new StreamWriter(ConfPath))
{
Wr.WriteLine("My content");
}
}
catch (IOException)
{
Thread.Sleep(DELAY_MS);
Retry++;
}
}
Is there a proper solution to my problem?