When I do such file access/manipulation I usually take care of two things.
First, for reading I use the following code (see FileShare enumeration):
using (Stream s = File.Open(path, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite)) { ... }
Second, I usually write a while loop for opening the file for reading/writing like this (draft code):
int tries=0;
while (tries < 10) {
try {
// try to open file for your operation
break;
} catch (IOException) {
tries++;
Thread.Sleep(200);
}
}
EDIT: Accidently I used FileShare.Read first time in my answer instead of the more appropriate FileShare.ReadWrite. Now I’ve corrected it.
2
solved How to read log from log file as it happens [closed]