2

Here is the downloading time when I click update button:

  • First time = 5 sec
  • After first time = 2 sec

Why it takes more time at first time? Without wc.Proxy = null; it took 2 minute at first time, is there anything else that slow it down?

Stopwatch sw = new Stopwatch();
sw.Start();
using (WebClient wc = new WebClient())
{
    wc.Proxy = null;
    wc.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0");
    wc.DownloadFile("http://example.com/folder/file.txt",@"folder/files/file.txt");
}
sw.Stop();
a1204773
  • 6,923
  • 20
  • 64
  • 94
  • Could it be the web server takes some time to process the first request, but after it has some of your data cached and can respond more quickly? – Joel Coehoorn Jan 03 '13 at 02:44
  • 1
    possible duplicate of [WebClient is very slow](http://stackoverflow.com/questions/6988981/webclient-is-very-slow) – Tofeeq Ahmad Jan 03 '13 at 04:31

1 Answers1

1

A possible solution to speed-up this process is caching. If the nature of the files/data that you are downloading is static, it is better to cache them on your web/app server.

Another solution would be firing the downloading process in a different UI thread, and possibility to use asynchronous process to free up your UI thread, to avoid freezing the application UI.

Here you are some references that might be helpful:

Community
  • 1
  • 1
Yusubov
  • 5,815
  • 9
  • 32
  • 69