How to change the timeout on a .NET WebClient object
You can extend the timeout: inherit the original WebClient class and override the webrequest getter to set your own timeout, like in the following example.
MyWebClient was a private class in my case:
private class MyWebClient : WebClient
{
protected override WebRequest GetWebRequest(Uri uri)
{
WebRequest w = base.GetWebRequest(uri);
w.Timeout = 20 * 60 * 1000;
return w;
}
}
Set timeout for webClient.DownloadFile()
Try WebClient.DownloadFileAsync()
. You can call CancelAsync()
by timer with your own timeout.
How to Set TimeOut for WebClient on .net?
From the MSDN Doc:
The Timeout property affects only synchronous requests made with the GetResponse method. To time out asynchronous requests, use the Abort method.
So if you are going to do an asynchronous request, I think you need to manage a timer of your own, and call .Abort() on the instance after whatever period of time.
There is some sample code showing this on this MSDN page for the .Abort()
method.
Related Topics
How to Get Dropdownlist Selectedvalue in Controller in MVC
Difference Between Ref and Out Parameters in .Net
Convert Integers to Written Numbers
How to Check Whether a String Is a Valid Http Url
How to Pass a Value from a Child Back to the Parent Form
How to Check If a Type Is a Subtype or the Type of an Object
Cast List<T> to List<Interface>
Object Cannot Be Cast from Dbnull to Other Types
Download/Stream File from Url - ASP.NET
How to Deserialize Xml into List<T>
Getting Value from Appsettings.JSON in .Net Core
Detailed Explanation of Variable Capture in Closures
Uwp Enable Local Network Loopback
All Possible Combinations of a List of Values
How to Correctly Implement a Backgroundworker with Progressbar Updates