Re: WebRequest problems
From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 06/04/04
- Next message: Lloyd Dupont: "typeof device"
- Previous message: Michael Kremser: "Re: WebRequest problems"
- In reply to: Michael Kremser: "Re: WebRequest problems"
- Next in thread: Michael Kremser: "Re: WebRequest problems"
- Reply: Michael Kremser: "Re: WebRequest problems"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 4 Jun 2004 13:22:05 +0100
Michael Kremser <moc.NOTUSEABLE.unyd.taerg@nuj4002pxe> wrote:
> > Ah yes - for some reason it doesn't seem to implement IDisposable in
> > the Compact Framework. You need to call Close() on it, in a finally
> > block.
>
> I can't see it's implementing IDisposable at all, at least there's no
> method "Dispose" also in the "big" fx.
There's WebResponse.IDisposable.Dispose - it's done by explicit
interface implementation. If you look at "about WebResponse class"
you'll see it implements IDisposable.
> > That *should* fix the problem, I believe. (I had a very similar bug a
> > while ago.)
>
> I now close the stream as well as the response, as shown below:
>
> WebRequest req = WebRequest.Create(strURL);
> WebResponse resp = req.GetResponse();
> using (StreamReader reader = new StreamReader
> (resp.GetResponseStream(), System.Text.Encoding.UTF7))
> {
> strResult = reader.ReadToEnd();
> reader.Close();
> }
> resp.Close();
>
> ...but there's still the same error. :-( I begin to wonder whether we
> work with a beta release of CF... :-/
And are you always executing that Close()? Don't forget that the reader
could be throwing an exception. You don't need to call reader.Close(),
by the way - the using statement will call Dispose for you.
> However, in another thread on this NG I found a link where a download of
> a file is being described:
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnne
> tcomp/html/AutoUpdater.asp
>
> I try this out and hope it helps. If not, I thought to just catch but
> ignore this exception (currently the user would get annoyed by a dialog
> box saying that the transfer failed - I will make a routine around the
> call that tries it maximum three times automatically if the problem
> persists).
I don't know whether doing things asynchronously will help - I believe
the problem is that there's a connection pool and if the responses
aren't being closed properly, those connections are all in use. Then
again, if resp.Close() *is* being executed in your code, that doesn't
account for the problem...
-- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
- Next message: Lloyd Dupont: "typeof device"
- Previous message: Michael Kremser: "Re: WebRequest problems"
- In reply to: Michael Kremser: "Re: WebRequest problems"
- Next in thread: Michael Kremser: "Re: WebRequest problems"
- Reply: Michael Kremser: "Re: WebRequest problems"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|