c# Multiple WebRequest and WebResponse timeout problems.

Hi Everyone ,

In this tips and tricks article i wanna talk about when we use Multiple WebRequest object for interacting some urls getting timeout errors even if remote server not busy.
this is usually caused by not dispose some open WebResponse objects.You can also use “using” statement for disposing unnecessery objects .

For good example :

WebRequest wrGETURL;
wrGETURL = WebRequest.Create(sURL);
// wrGETURL.Proxy = myProxy;

durationTime = DateTime.Now;

using
(HttpWebResponse response = (HttpWebResponse)wrGETURL.GetResponse())
{
status = response.StatusCode.ToString();
TimeSpan ts = DateTime.Now – durationTime;
duration = ts.TotalMilliseconds.ToString();
}

Advertisements