I could not find a way to cancel / terminate the asynchronous read operation after a successful HttpWebRequest. Unable to set timeout, ThreadPool.RegisterWaitForSingleObject does not work either. And closing the base socket is not an option, because neither HttpWebRequest / Reponse provides access to it.
Edit:
Unfortunately, this approach that Sunny advises only works for HttpWebRequest.BeginGetResponse. For the stream that you get after GetResponseStream () for some reason RegisterWaitForSingleObject does not work - the callback is never called.
The situation is this: I got an application that uses HttpGetRequest. It is created using the standard MSDN example for async httpwebrequest. Getting an answer works like a charm. But in rare cases, the server my httpwebrequest is connecting to forgets to close the socket. So I hung on an endless read from BeginRead.
In some cases, another server forgets
Daniel Iankov
source
share