Click here to Skip to main content
15,941,828 members
Please Sign up or sign in to vote.
3.12/5 (3 votes)
See more:
       WebClient web = new WebClient();
       var byt = web.downloaddat(path)

This code download data very slowly even application got stuck or hang.`enter code here.


What I have tried:

I set proxy = null ;
but for first time it not work and second time it works.
Posted
Updated 8-Mar-17 1:16am

Here, try using

WebProxy proxy = WebProxy.GetDefaultProxy()
client.Proxy = proxy;


Or for the first time you can override the timeout function and set timeout for webclient, on timeout call your function again to download data this will solve your issue where it is not working for the first time.

public class WebClientWithTimeout:WebClient
{
    protected override WebRequest GetWebRequest(Uri address)
    {
        WebRequest wr = base.GetWebRequest(address);
        wr.Timeout = 5000; // timeout in milliseconds (ms)
        return wr;
    }
}


Can check this link for more detail : C# Download URL to string or file with timeout using WebClient[^]
 
Share this answer
 
Download speed is a function of the amount of data, the speed of your connection, and the speed of the local and remot host. you could try asynchronous downloading, see WebClient.DownloadData Method (String) (System.Net)[^].
 
Share this answer
 
If your application hangs you are probably calling DownloadData from your main (GUI) thread:
This method blocks while downloading the resource. To download a resource and continue executing while waiting for the server's response, use one of the DownloadDataAsync[^] methods.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900