Re: Strange behavior when closing stream

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
.



Relevant Pages

  • Re: Read macro for one of two ideas
    ... If we had an overscore character then only underscores and overscores ... breaking somehow or working differently when your (, reader is present? ... the character that was read from the stream). ... (defun paren-close-reader (stream char) ...
    (comp.lang.lisp)
  • Re: Read macro for one of two ideas
    ... If we had an overscore character then only underscores and overscores ... breaking somehow or working differently when your (, reader is present? ... the character that was read from the stream). ... (defun paren-close-reader (stream char) ...
    (comp.lang.lisp)
  • Re: Read macro for one of two ideas
    ... breaking somehow or working differently when your (, reader is present? ... the character that was read from the stream). ... (defun paren-close-reader (stream char) ...
    (comp.lang.lisp)
  • Re: Calling close on StringReader (or not)
    ... Stream object, which do require disposing. ... these readers deal with unmanaged resources. ... using (StreamReader reader = new StreamReader( ...
    (microsoft.public.dotnet.framework)
  • Re: Read macro for one of two ideas
    ... breaking somehow or working differently when your (, reader is present? ... but it's a bit of an advanced hack. ... the character that was read from the stream). ... (defun paren-close-reader (stream char) ...
    (comp.lang.lisp)