I have a small application that has a timer with a 10s interval. The event off this timer instantiates a local FileStream object, reads the file, then closes the stream.
The file I am reading changes every few minutes (it's basically a dump of the current song from a music player). The problem I am running into is that after about 10 minutes the FileStream starts supplying old content. I have placed break points in the file and simultaneously pulled up the current content of the file and the FileStream will be reporting content from several changes back (10-15 minutes prior).
I'm wondering if anyone has run into this issue before or if I am missing the FileStream.OpenTheDangFile_NoReally() function.
The function that opens the filestream is as follows:
These vasriables are local to the function and there are no other variables with the same names in the app, so I don't believe it is a scope issue.
The really nifty thing is that if I stop and Start the Timer object it will actually start picking up the real file again for a while, then it will stop and continue to read the same copy of that file no matter how much the file changes.
The file I am reading changes every few minutes (it's basically a dump of the current song from a music player). The problem I am running into is that after about 10 minutes the FileStream starts supplying old content. I have placed break points in the file and simultaneously pulled up the current content of the file and the FileStream will be reporting content from several changes back (10-15 minutes prior).
I'm wondering if anyone has run into this issue before or if I am missing the FileStream.OpenTheDangFile_NoReally() function.
The function that opens the filestream is as follows:
Code:
Try
Dim fs As New IO.FileStream(txtFilePath.Text, IO.FileMode.Open, System.IO.FileAccess.Read)
Dim sr As New IO.StreamReader(fs)
Dim s As String = sr.ReadToEnd()
sr.Close()
fs.Close()
txtData.Lines = s.Split(vbLf)
Catch ex As Exception
txtData.Lines = New String() {"VB.Net Exception", "Arrrgh", "Arrrgh"}
End Try
These vasriables are local to the function and there are no other variables with the same names in the app, so I don't believe it is a scope issue.
The really nifty thing is that if I stop and Start the Timer object it will actually start picking up the real file again for a while, then it will stop and continue to read the same copy of that file no matter how much the file changes.
