简体   繁体   中英

Display ProgessBar when downloading with WebClient in C#

I am using this code to download multiple file. My problem is that it downloads them all at one time and what I want to do is have the progress bar show each file downloaded to 100% then go to the next file. I mean I want the first file to download and go to 100% in progress bar then the second one and start the progress bar again till 100% and so on. But in my code it just has one progressbar that shows the progress for all files being downloaded at once. How can I do this?

WebClient webClient = new WebClient();

webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);

webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged); //Progress Bar Handler

webClient.DownloadFileAsync(new Uri("http://www.somesite.com/Update/Updates.zip.001"), @"Updates.zip.001");
webClient.DownloadFileAsync(new Uri("http://www.somesite.com/Update/Updates.zip.002"), @"Updates.zip.002");

You can start downloading the second file in the Completed handler for the first file.

However, you should stick with your current behavior; it's better to download both files at once.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM