Why does the following code Timeout the second (and subsequent) time it is run?
The code hangs at:
using (Stream objStream = request.GetResponse().Ge
As you have stated, running fiddler in the background would mitigate the issue. This is because fiddler force closes any responses. Extending on the above post from Sam B I would ensure that the response is closed like so:
using (var wresponse = request.GetResponse())
{
using (Stream objStream = wresponse.GetResponseStream())
{
// ...
}
wresponse.close();
}
Also it may be worth setting the proxy to null like so:
request.Proxy = Null;
As the .NET framework will go out searching for a proxy unless you explicitly do this. When fiddler is running this effect would be mitigated as fiddlers proxy would be found directly.
The WebResponse
obtained by request.GetReponse()
MUST be disposed properly. Try this (removing request.Abort()
and GC.Collect()
calls):
using (var wresponse = request.GetResponse())
{
using (Stream objStream = wresponse.GetResponseStream())
{
// ...
}
}
Edit: Since it still does not work, I suggest you to test this with an empty windows application. This way, you could isolate app.config problems or maximum concurrent calls per host* (are you using other webrequest object somewhere else in your application to this host; which webresponse are not disposed properly?).
Hope this solve your problem, I am out of ideas!