I am using the StreamReader class very successfully to open and process a text file. However there is one small problem which I need to design for.
The text file arrives at a known location from an external process over which I have no control. Because of the way this is implemented most of the time this isn't going to cause me any problem.
However, there is the chance that my application might try to open the file whilst it is still being written by another external process.
How do I go about ensuring I have sole access to a text file? I don't mind having a delay-and-retry loop, but I'm struggling to understand how I can code the decision logic.
The StreamReader class is instantiated as follows:
Dim oTxt As New System.IO.StreamReader(FilNam)
I'm not sure how to go about coding the retry loop.
The text file arrives at a known location from an external process over which I have no control. Because of the way this is implemented most of the time this isn't going to cause me any problem.
However, there is the chance that my application might try to open the file whilst it is still being written by another external process.
How do I go about ensuring I have sole access to a text file? I don't mind having a delay-and-retry loop, but I'm struggling to understand how I can code the decision logic.
The StreamReader class is instantiated as follows:
Dim oTxt As New System.IO.StreamReader(FilNam)
I'm not sure how to go about coding the retry loop.
Last edited: