3

My objective is to get the answer from up to 6000 Urls in the shortest time. It was working very well (12 seconds for 5200 LAN Addresses) until some delay started to happen.

My code uses up to 20 simultaneous HttpWebRequest.BeginGetResponse with ThreadPool.RegisterWaitForSingleObject for timeout handling.

However some (up to 4 in 5,000) of the requests never hit the TimeoutCallback function with the second parameter (timedOut) true, and they waste 5 minutes of my precious time until they hit theBeginGetResponseCallback function and then raise a WebException. The exceptions says something like "the operation reached the time limit", but as the exception message is in portuguese(my native language) I couldn't Google it.

I wonder if I can reduce this time limit to 20 seconds for example. Anyone knows how? I've already tried:

<system.web>
    <httpRuntime executionTimeout="20"/>
</system.web>

But as I'm running it as a Console Application, ASP.NET configurations don't work. And I also tried:

myHttpWebRequest.Timeout = 20*1000;

And

ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), AsyncState, 20*1000, true);

Without success. Can you help me?

Update What I am trying to say is there are 4 possible results for an asynchronous HTTP request:

  1. Never reach the callback function -> timeout callback function
  2. Reaches and answers successfully
  3. Reaches and raises an exception
  4. Delay exactly 5 minutes until raise an "time limit" web exception inside the callback function

The 4th possibility is the one is delaying my Application, and I don't know how to shorten that delay

Update Is there a possibility that the method GetResponseStream instead of the GetResponse is who causes the timeout?

xan
  • 7,440
  • 8
  • 43
  • 65
Jader Dias
  • 88,211
  • 155
  • 421
  • 625

2 Answers2

4

It sounds like you need to set the ReadWriteTimeout property of the request object.

http://blogs.msdn.com/buckh/archive/2005/02/01/365127.aspx

  • Thanks, perhaps that's the solution. But as I'll have to wait untill the problem occurs again to test it. – Jader Dias Dec 24 '08 at 13:11
  • Your comment in the post below hits it right on the head. Asynchronous web requests ignore the timeout property. So unless you have rolled your own asynchronous timeout event, the timeout of the web request is going to be based on the ReadWriteTimeOut and not the webrequest timeout. –  Dec 26 '08 at 15:51
  • Can the defaults be set in standard MS configuration files? – Michael Freidgeim Jun 14 '12 at 04:16
1

.Timeout = time spent trying to establish a connection (not including lookup time) .ReadWriteTimeout = time spent trying to read or write data after connection established

Benhar Upasana
  • 235
  • 2
  • 9