Here's what I understand about using HttpWebRequest to make a request asyncronously:
The essential structure for making an asynchronous web request is to call BeginGetResponse() and start a timer at the same time. If the response doesn't timeout, BeginGetResponse() will call a callback method that will call EndGetResponse() and read the response. If the response does timeout, a different callback method to the timer gets called and WebRequest.Abort() is invoked.
This structure hinges on the fact that Abort() and EndGetResponse() are exclusive. Calling Abort() after EndGetResponse() has basically no effect and calling EndGetResponse() after Abort() causes EndGetResponse() to throw an exception which can then be caught and handled however you want to handle timeouts.
My problem is when I need to make several hundred requests per second to several services and one service starts becoming very, very latent. The Timeout callback might get called after 500ms and calls Abort() and my program continues happily. But because the service still hasn't returned 10 seconds later, the first thread started by BeginGetResponse() is still waiting and the network connection resource is unavailable for use by any future requests.
Is there any way to have a timeout free up the resources of the thread that is supposedly timing out? If not, is there something like a Web.config value that I can set that will timeout the request on a different layer of the network than the application?