A
Andrew Cooper
I posted this before but apparently it was eaten by the great Internet gods.
I've got an application that watches a file. When that file is changed
the application reads the data on the file and does stuff with it. In
the application I have the following code in an event.
....
....
Dim fs As FileStream
Dim sr As StreamReader
<do stuff here>
fs = File.OpenRead(path)
sr = New StreamReader(fs)
<do stuff here>
fs = Nothing
sr = Nothing
End Sub
The first time the file is changed, the code works fine. The problem is
that after the first time the file never gets released by my application
so nothing else can actually change the file because it "is currently
being used by another program." So, the program works once and then the
file can't get changed again. That's not useful, obviously.
Is there some way to release the file that I'm not aware of? I thought
setting the Stream and the Reader to Nothing would do the trick and I
don't see a method on either of those to actually let go of the file. I
even tried File.Delete(path) just for grins and giggles but that gives
me the "File is currently being used by another program." too.
Any help would be greatly appreciated.
Andrew Cooper
I've got an application that watches a file. When that file is changed
the application reads the data on the file and does stuff with it. In
the application I have the following code in an event.
....
....
Dim fs As FileStream
Dim sr As StreamReader
<do stuff here>
fs = File.OpenRead(path)
sr = New StreamReader(fs)
<do stuff here>
fs = Nothing
sr = Nothing
End Sub
The first time the file is changed, the code works fine. The problem is
that after the first time the file never gets released by my application
so nothing else can actually change the file because it "is currently
being used by another program." So, the program works once and then the
file can't get changed again. That's not useful, obviously.
Is there some way to release the file that I'm not aware of? I thought
setting the Stream and the Reader to Nothing would do the trick and I
don't see a method on either of those to actually let go of the file. I
even tried File.Delete(path) just for grins and giggles but that gives
me the "File is currently being used by another program." too.
Any help would be greatly appreciated.
Andrew Cooper