【发布时间】:2011-10-06 14:34:40
【问题描述】:
我使用以下代码从我的网络服务器下载 50 多个文件
private void button5_Click(object sender, EventArgs e)
{
WebClient client = new WebClient();
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
//downloads
client.DownloadFileAsync(new Uri("http://www.site.com/file/loc.file"), @"c:\app\loc ");
client.DownloadFileAsync(new Uri("http://www.site.com/file/loc.file"), @"c:\app\loc ");
client.DownloadFileAsync(new Uri("http://www.site.com/file/loc.file"), @"c:\app\loc ");
}
void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
double bytesIn = double.Parse(e.BytesReceived.ToString());
double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
double percentage = bytesIn / totalBytes * 100;
progressBar.Value = int.Parse(Math.Truncate(percentage).ToString());
}
private void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
MessageBox.Show("Game Update Finished!");
}
我想一次下载 1 个文件并带有一个持续的进度条 iv 完成了大部分编码,但是当我点击“下载”按钮时,我收到以下错误
WebClient 不支持并发 I/O 操作。
我需要做什么?
【问题讨论】:
-
只是你试图写入同一个文件
标签: c# windows winforms .net-4.0