How to deal with the this Exception. I have a text file. And this code rewrites the file every 3 sec. At the same time another MS Excel file reads the data from the file. And sometimes I get this exception.
Is there a way for StreamWriter to wait until MS Excel finishes reading the file and start rewriting the file right after that?
string path = @"C:\My Path\my_file.txt";
using (StreamWriter fs = new StreamWriter(File.OpenWrite(path)))
{
fs.Write(text);
fs.Close();
}