I have the following code (from this question):
public class TimedWebClient : WebClient
{
// Timeout in milliseconds, default = 600,000 msec
public int Timeout { get; set; }
public TimedWebClient()
{
this.Timeout = 600000;
}
protected override WebRequest GetWebRequest(Uri address)
{
var objWebRequest = base.GetWebRequest(address);
objWebRequest.Timeout = this.Timeout;
return objWebRequest;
}
}
string text = new TimedWebClient { Timeout = 500 }.DownloadString(url); //a url
However, if the url goes offline while the string is being downloaded, the TimedWebClient does not timeout and will just hang. Any ideas how to solve this problem?