Asynchronous WebRequest Timeout bug

G

Guest

http://msdn2.microsoft.com/en-us/library/21k58ta7.aspx

I'm using that example as my starting point. The timeout it has though is
not bulletproof. It will timeout if it doesn't connect within the timeout
period, but if it connects and the server sends 1 byte and then hangs the
connection open, it will not timeout. I'd like to include another timeout
(let's say 10 seconds) for the read not finishing (or alternatively a timeout
that encompasses the entire process or opening a connection and getting the
response).

Im RespCallback I tried to add another WaitForSingleObject call, but it
didn't seem to help.

// Begin the Reading of the contents of the HTML page and
print it to the console.
IAsyncResult asynchronousInputRead =
responseStream.BeginRead(myRequestState.BufferRead, 0, BUFFER_SIZE, new
AsyncCallback(ReadCallBack), myRequestState);

//ADDED - Added a timeout to confirm that data finishes
reading

ThreadPool.RegisterWaitForSingleObject(asynchronousInputRead.AsyncWaitHandle,
new WaitOrTimerCallback(TimeoutCallback), myHttpWebRequest,
DefaultReadTimeout, true);

Any ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top