My goal is to get an answer from 6000 addresses as soon as possible. It worked very well (12 seconds for 5200 LAN addresses) until some kind of delay started.
My code uses up to 20 concurrent HttpWebRequest.BeginGetResponse s ThreadPool.RegisterWaitForSingleObjectto handle timeout.
However, some (up to 4 out of 5000) requests never get into the TimeoutCallback function with the second parameter (timedOut) true, and they spend 5 minutes on my precious time until they get into the BeginGetResponseCallback function, and then raise the WebException. The exceptions say something like "the operation has reached the deadline," but since the exception message is in Portuguese (my native language), I could not use it on Google.
I wonder if I can reduce this time interval to 20 seconds, for example. Does anyone know how? I already tried:
<system.web>
<httpRuntime executionTimeout="20"/>
</system.web>
But since I run it as a console application, ASP.NET configurations do not 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'm trying to say is that there are 4 possible results for an asynchronous HTTP request:
- Never execute callback function -> timeout callback function
- Achievements and Answers Successfully
- Reaches and throws an exception
- Set aside exactly 5 minutes until the time limit web exception closes inside the callback function
The fourth possibility is the delay of my application, and I do not know how to reduce this delay
, GetResponseStream GetResponse ?