使用Async下载多个文件
本文关键字:文件 下载 Async 使用 | 更新日期: 2023-09-27 18:13:13
我有这段代码,可以很好地下载一个文件。
我如何添加多个文件下载此代码?
private void Form1_Load(object sender, EventArgs e)
{
WebClient client = new WebClient();
client.DownloadProgressChanged += Client_DownloadProgressChanged;
client.DownloadFileCompleted += Client_DownloadFileCompleted;
client.DownloadFileAsync(new Uri("http://download.thinkbroadband.com/10MB.zip"), @"c:'folder'10MB.zip");
}
private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
MessageBox.Show("completed");
}
private void Client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar1.Maximum = (int)e.TotalBytesToReceive / 100;
progressBar1.Value = (int)e.BytesReceived / 100;
}
您可以创建多个进度条和多个web客户端。各WebClient
应使用相应的进度条