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.
精彩评论