I'm trying to allow just one process be able to write to a file and other processes could only read it , so I tried to open the file by:
sw = new StreamWriter(File.Open(filepath, FileMode.Create, FileAccess.Write, FileShare.Read)
);
and then there is a write loop:
while(true)
{
//some code
sw.Write(message);
}
sw.close();
while this process writes to the file, I tried to open it manually I recive a message to open the file in readonly mode , when I press "readonly" button the writer process throws exception "System.IO.IOException: The process cannot access the file because another process has locked a portion of the file."
how I could fix it ?