Hello,
We have a simple piece of code that exchanges data using HTTP
request/reponse. It uses "using" statement to guarantee that the
communication channel is properly closed on completion. However, if the code
is executed multiple times, the first execution attempt works fine, but the
second attempt times out.
To verify if the channel is closed properly, we replaced that code with the
following:
HttpWebRequest request = PrepareRequest(userVerificationData,
schufaRequestType, null);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string requestID = response.Headers["RequestID"];
try
{
// Do something
}
finally
{
request = null;
response = null;
GC.Collect();
}
Then suddently everything worked! But the difference is that now we call
expensive garbage collection which of course kills the performance.
Why using Dispose method does not do the same? Isn't it the purpose of
IDisposable interface?
Vagif Abilov
Oslo Norway
Jon Skeet [C# MVP] - 05 Jul 2006 20:52 GMT
> Hello,
>
[quoted text clipped - 3 lines]
> is executed multiple times, the first execution attempt works fine, but the
> second attempt times out.
<snip>
> Why using Dispose method does not do the same? Isn't it the purpose of
> IDisposable interface?
Yes. Could you show us the code that doesn't work, preferrably as a
short but complete program?

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Vagif Abilov - 05 Jul 2006 21:47 GMT
I am not in the office right now, but I guess the original code looked like
this:
HttpWebRequest request = PrepareRequest(...);
using(HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
... do something with response
}
HttpWebRequest is not disposable, so we applied "using" pattern to
HttpWebResponse object only.
While searching for the source of the problem, I found couple of documents:
http://dturini.blogspot.com/2004/06/on-past-few-days-im-dealing-with-some.html
http://support.microsoft.com/?kbid=831138
Looks like there .NET 1.1 had a problem with release of unmanaged resources
allocated by HttpResponse. Does .NET 2.0 has the same problem?
Vagif
>> Hello,
>>
[quoted text clipped - 13 lines]
> Yes. Could you show us the code that doesn't work, preferrably as a
> short but complete program?
Jon Skeet [C# MVP] - 05 Jul 2006 22:27 GMT
> I am not in the office right now, but I guess the original code looked like
> this:
[quoted text clipped - 16 lines]
> Looks like there .NET 1.1 had a problem with release of unmanaged resources
> allocated by HttpResponse. Does .NET 2.0 has the same problem?
Hmm. Glad you've found it. I *suspect* that .NET 2.0 doesn't have the
same problem, given that it was fixed against 1.1 in the hotfix. I
wouldn't like to say for sure though.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Vagif Abilov - 05 Jul 2006 22:53 GMT
Well, the problem we discovered was actually in our code running on .NET 2.0
:-(
We will investigate more, but first impression - the problem is still there,
since "using" does not work and GC.Collect does.
Vagif
>> I am not in the office right now, but I guess the original code looked
>> like
[quoted text clipped - 23 lines]
> same problem, given that it was fixed against 1.1 in the hotfix. I
> wouldn't like to say for sure though.
Barry Kelly - 05 Jul 2006 21:02 GMT
> We have a simple piece of code that exchanges data using HTTP
> request/reponse. It uses "using" statement to guarantee that the
[quoted text clipped - 4 lines]
> To verify if the channel is closed properly, we replaced that code with the
> following:
I'm not sure I understand - can you show us the code that didn't work,
rather than the code that did? :)
-- Barry

Signature
http://barrkel.blogspot.com/
Vagif Abilov - 05 Jul 2006 21:48 GMT
Please see my reply to Jon Skeet.
Best regards
Vagif
>> We have a simple piece of code that exchanges data using HTTP
>> request/reponse. It uses "using" statement to guarantee that the
[quoted text clipped - 12 lines]
>
> -- Barry