Is WebClient.DownloadFileAsync really slow?

I use the DownloadFileAsync WebClient method to download some files from the server, and I cannot help but notice that in my unofficial testing of my code in VS2010 it blocks for about 3 seconds, this starts, which, in my opinion, hits the target in the first place.

Here is the relevant code snippet:

 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 use DownloadFileAsync to block the user interface when the application downloads a 100 MB file. Obviously, if the user interface is blocked for 3 seconds at the start of the call, this reduces the utility, if not completely.

I am relatively inexperienced with C # /. NET (I did a bunch of .Net 2.0, about 3-4 years ago, IIRC, but now I mainly retrain it).

+7
performance c # webclient downloadfileasync
source share
4 answers

In addition to what Nav says, it seems like the problem is auto-detecting the proxy , see this answer: Why is this WebRequest code slow?

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

+8
source share

I read somewhere that DownloadFileAsync actually checks the DNS name in a blocking thread, so why can you slow down. If you entered the IP address directly, there should be no blockage. A piece of information found here: http://www.csharp-examples.net/download-files/

+7
source share

Have you found out if there is a delay in your application or network? To find out if the destination server is slow, start Wireshark and see when the first response is received after sending the request. Maybe this is where the delay occurs?

Also, if this is part of a large application, then the first time will always be slow due to startup costs. If you really want to get a good measurement, measure the total time required for the 1st call, and for the 2nd to 10th call. From this, you can find out if the delay is a startup cost or every time.

0
source share

in ASP.NET, using the async method does not make sense if the thread role is expected from the aysnc method.
When I run async for webclient, it always joins when the main thread finishes (before aspx rendering).

excellent related article: http://weblogs.asp.net/gunnarpeipman/archive/2010/09/07/making-asynchronous-calls-to-web-services-during-asp-net-page-processing.aspx

enter image description here

Here's more info about it: an asynchronous WebClient call not called in ASP.NET MVC

-one
source share

All Articles