Re: StreamWriter Problem
- From: kimiraikkonen <kimiraikkonen85@xxxxxxxxx>
- Date: Fri, 7 Dec 2007 16:01:45 -0800 (PST)
On Dec 8, 1:45 am, Tom Shelton <tom_shel...@xxxxxxxxxxx> wrote:
On Dec 7, 4:23 pm, kimiraikkonen <kimiraikkone...@xxxxxxxxx> wrote:
Edit: However, i added a catch ex as exception handler and received
the exception as "the file is being used by another process" although
nothing is open except my program.
Is it a streamwriter bug? Because nothing is using a text file while
i'm trying to save through my project.
no, it's not a bug in the streamwriter - it's a bug in your code. and
if your code for loading the file is similar to the saving code, then
i can see why. you are never closing the resource. you need to call
close on the streamwriter (and streamreader) when you are done with
them....
using sr as new streamreader(myfile)
' do stuff
end using
using the using block will ensure that the streamreader is properly
cleand up when the block ends. Basically, it will compile like you
had done something like:
dim sr as streamreader = nothing
try
sr = new streamreader(myfile)
' do stuff
finally
if not isnothing(sr) then
sr.dispose()
end finally
you need to do the same with your streamreader.
--
Tom Shelton
I was using this for streamwriter also of streamreader before i posted
with no help:
Try
......
Catch
Finally
If Not myStreamWriter Is Nothing Then
myStreamWriter.Close()
End If
.
- Follow-Ups:
- Re: StreamWriter Problem
- From: Tom Shelton
- Re: StreamWriter Problem
- References:
- StreamWriter Problem
- From: kimiraikkonen
- Re: StreamWriter Problem
- From: kimiraikkonen
- Re: StreamWriter Problem
- From: Tom Shelton
- StreamWriter Problem
- Prev by Date: Re: StreamWriter Problem
- Next by Date: Re: SCOPE_IDENTITY and parameters during insert
- Previous by thread: Re: StreamWriter Problem
- Next by thread: Re: StreamWriter Problem
- Index(es):
Relevant Pages
|
Loading