Sorry, this code is impossibly bad. Why doing all that stuff. Every time you say
Thread.Sleep(300)
; especially with hard-coded "300", the question would be: "why not 310, why not 200?". If fact, it all makes no sense at all.
string fileName =
using (StreamReader reader = new StreamReader(fileName)) {
string someData = reader.ReadLine();
}
And nothing else. There is no need to retry. Instead, do some effort to work with the files not touched by other processes. But it the file is opened by some other process, retrying is just silly. Instead, stop trying immediately.
Don't use try-catch on too local level. Do it when you really know what to do with the exception (I call it "competency points"), often only on the very top stack frame of the thread. Exception have been invited to isolate exception handling, not to mix them with code.
—SA