0

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

user1737538
  • 497
  • 2
  • 7
  • 16
  • 1
    possible duplicate of [How can I read a text file without locking it?](http://stackoverflow.com/questions/3448230/how-can-i-read-a-text-file-without-locking-it) – Pete Garafano May 15 '14 at 14:52
  • 1
    "Maybe the "official" logger application asks for an exclusive lock" - that'd be my guess as well. – CodesInChaos May 15 '14 at 15:19

0 Answers0