0

I can't seem to figure out how to download multiple files using DownloadFileAsync. How can I input a list as a URI?

My current code for a single download looks like this:

        WebClient client = new WebClient();
        client.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0)");
        client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
        client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);

        // Starts the download
        client.DownloadFileAsync(new Uri(chosenVersion), tbFolder.Text + chosenVersionFileName);   

'chosenVersion' is just a link, say example.com/some.jpeg.

I just want to get all the downloads bundled into one progress bar while downloading at the same time.

Carl
  • 249
  • 2
  • 5
  • 13
  • http://stackoverflow.com/questions/6992553/how-do-i-async-download-multiple-files-using-webclient-but-one-at-a-time/6992743#6992743 http://stackoverflow.com/a/2042428/342740 – Prix Mar 26 '15 at 03:28

1 Answers1

0

I just want to get all the downloads bundled into one progress bar while downloading at the same time.

An instance of WebClient can handle just one download at a time. You can modify the approach given in

https://stackoverflow.com/a/6992743/141172

to download multiple files in parallel by replacing the queue with a construct such as a List<string> and using Parallel.Foreach() to process the list concurrently.

Community
  • 1
  • 1
Eric J.
  • 147,927
  • 63
  • 340
  • 553