I need to read a text file while another application is writing to it. In this scenario I've programmed:
Dim _fs_ As FileStream = File.Open("c:\log.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
Dim _sr_ As New StreamReader(_fs_)
What I can see is that the other application cannot write to the file until I close the file with
_sr_.Close()
Is FileShare.ReadWrite really working? Any other way to get this file sharing working?
Thank you in advance
EDIT: I tried to investigate further and coded a small application by my self that writes to the log file I need to read: in that application I open the file as follows
Dim _fs_ As FileStream = File.Open("c:\log.txt", FileMode.Append, FileAccess.Write, FileShare.ReadWrite)
Dim tw As New StreamWriter(_fs_)
My small test application can write to the log while the other is reading: so FileShare flag does work. Maybe the "official" logger application (which I didn't personally write) asks for an exclusive lock on the file to be able to write to it (as one of you already suggested). I will ask the programmer!
Thank you all