sorry i posted on the end of a solved post so I thought i would bring it out as a fresh post.

I'm trying to monitor a log file. this log updates several time per second at times and im trying to open it read each line to a text box and based on what those lines contain take other actions.

After reading to the end of the file i close it and open a writer to clear it so im not reading the same text twice.

The problem comes from the routine firing so quickly back to back that the reader.close() does no release the process in time for it to open again. I need it to be as close to real time as possible

I get the "file in use by another application" error. Is there something simple im missing? Apologies if this is already solved. I'm still learning.

It works perfectly the first time the file changes but if there is not a 20 second pause between each call from the monitoring routine i get the error.


Thanks in advance for any help.
****




Public Sub logupdate(ByVal Source As Object, ByVal e As System.IO.FileSystemEventArgs)
Dim Reader As TextReader


Reader = New StreamReader(e.FullPath)
Dim readText As String

While Reader.Peek <> -1
readText = Reader.ReadLine()



Me.TextBox1.Text = readText
Select Case Mid(TextBox1.Text, 1, 2)
Case "hi"
Me.Label1.Text = "WE got a hit!"
Case Else
Me.Label1.Text = "We've got nothing!"
End Select

End While
numLines = lineCount


Reader.Close()



Call logclear()
Reader = Nothing




End Sub
****
Public Sub logclear()
Dim sw As StreamWriter
sw = File.CreateText("filepath.txt")



sw.Close()
End Sub