I need to download some large files, so I need a longer DownloadFile() timeout than the default 1 minute.
Problem is that my solution doesn't increase the timeout. It stays at 1 minute.
I have created this class:
public class MyWebClient : WebClient
{
private int timeout;
public int Timeout
{
get
{
return timeout;
}
set
{
timeout = value;
}
}
public MyWebClient()
{
this.timeout = 1200000;
}
protected override WebRequest GetWebRequest(Uri uri)
{
WebRequest w = base.GetWebRequest(uri);
w.Timeout = this.timeout;
return w;
}
}
Calling it like this:
using (MyWebClient client = new MyWebClient())
{
client.Timeout = 1200000;
client.DownloadFile(new Uri(fileUrl), localFile);
}
Any ideas?