Re: Strange behavior when closing stream
- From: John Kraft <jhkraft@xxxxxxxxxxxxxxx>
- Date: Tue, 24 Oct 2006 12:22:39 -0500
On 24 Oct 2006 08:37:58 -0700, "ssamuel" <ssamuel@xxxxxxxxx> wrote:
John,
I don't know too much about the details of your stream -- they tend to
be idiosynchratic -- but try a
using (StreamReader reader = new
StreamReader(response.GetResponseStream()))
{
...
}
block around your reader. You should be able to avoid the call to
Close(), which may solve your problem.
What do you expect to be happening after your Close() call anyway?
Looks like there may be some threading issues. Do you have a try/catch
block around the thread boundary of the background thread?
Stephan
Thanks for the reply, Stephan.
I just tried that possibility. What I discovered is that when the
compiler gets to the closing brase of the using statement, the method
terminates exactly the way it did with the Close method.
What I expect to happen, is for the method to complete execution. Out
of habit, I always close my readers before i close my writers. In
this case, the premature exiting of the method causes the
writer.Close() and subsequent instructions to not execute. The has
the side effect of keeping the output file "locked" until I exit the
application. This causes me to be unable to perform the necessary
parsing of the files at a later point in the application.
Aside from those effects, I don't want to be hogging up system
resources anywhere by having an open stream to a server on the
internet; especially if users decide to cancel the download and
restart it at a later time.
Thanks,
John
.
- Follow-Ups:
- Re: Strange behavior when closing stream
- From: ssamuel
- Re: Strange behavior when closing stream
- References:
- Strange behavior when closing stream
- From: John Kraft
- Re: Strange behavior when closing stream
- From: ssamuel
- Strange behavior when closing stream
- Prev by Date: Re: Problems pulling info from Form1 to Form2
- Next by Date: Re: Trying to understand interfaces
- Previous by thread: Re: Strange behavior when closing stream
- Next by thread: Re: Strange behavior when closing stream
- Index(es):
Relevant Pages
|