WebRequest.Timeout has no effect

  • Thread starter Thread starter aaronfude
  • Start date Start date
A

aaronfude

Hi,

I'm running the following code to read a URL into a string. When the
url is offline, it times out after about 10 seconds regardless of what
I set myRequest.Timeout to.

Any suggestions?

WebRequest myRequest = WebRequest.Create (inURL);
WebResponse myResponse = myRequest.GetResponse();

myRequest.Timeout = 1000;
Stream myStream = myResponse.GetResponseStream ();
StreamReader myReader = new StreamReader (myStream);

string s = myReader.ReadToEnd();

Many thanks in advance.

Aaron Fude
 
Hi,

I'm running the following code to read a URL into a string. When the
url is offline, it times out after about 10 seconds regardless of what
I set myRequest.Timeout to.

Any suggestions?


Let me quote MSDN:

"Timeout is the number of milliseconds that a synchronous request made
with the GetResponse method waits for a response, and the
GetRequestStream methods waits for a stream. [...]"

This doesn't cover any timeout that may occur at lower levels of the
TCP/IP stack -- which is exactly what you have if the remote host is
offline.

Cheers,
 
Back
Top