Is WebClient.DownloadFileAsync really this slow?

davidtbernal picture davidtbernal · Jun 4, 2010 · Viewed 7k times · Source

I'm using the DownloadFileAsync method of WebClient to download some files from a server, and I can't help but notice that in my informal testing of my code within VS2010, it blocks for about 3 seconds while it starts, which, in my opinion kind of defeats the purpose in the first place.

Here is the relevant snippet of code:

WebClient downloader = new WebClient();
downloader.DownloadProgressChanged += new DownloadProgressChangedEventHandler(updateDownloadProgress);
downloader.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(downloadCompleted);

var current_map = map_downloads[0];//string with filename, map_downloads is List<string>

var path = System.IO.Path.GetTempFileName();

downloaded_maps.Add(path);//adding the temp file to a List<string>

downloader.DownloadFileAsync(new Uri(MAP_BASE + current_map), path); //MAP_BASE is a string containing the base url

I'm using DownloadFileAsync to keep the UI from blocking while the application downloads a ~100 MB file. Obviously if the UI blocks for 3 seconds while the call starts, that diminishes the utility somewhat, if not entirely.

I'm relatively inexperienced with C#/.Net (I did a bunch of .Net 2.0 stuff about 3-4 years ago, IIRC, but I'm basically relearning it now).

Answer

Igor Brejc picture Igor Brejc · Sep 26, 2010

In addition to what Nav says, it looks like the problem is web proxy autodetection, see this answer: Why is this WebRequest code slow?

I tested it and it now works without any significant delay during the first call.