2011-10-28 61 views
0

我试图根据用户在表单上选择的内容下载多个文件。 我有多个复选框,所以如果用户选择复选框1,3,4我想让webclient下载文件1.txt,3.txt,4.txt。 WebClient方法导致“WebClient不支持并发I/O操作”。错误。VB - 使用DownloadFileASync(WebClient)进行多次下载

If chk1.Checked Then 
     WC.DownloadFileAsync(New Uri("http://www.google.com/1.txt), Path.Combine(DataSource & strDirectory, "1.txt")) 
    End If 
If chk2.Checked Then 
     WC.DownloadFileAsync(New Uri("http://www.google.com/2.txt), Path.Combine(DataSource & strDirectory, "2.txt")) 
    End If 
If chk3.Checked Then 
     WC.DownloadFileAsync(New Uri("http://www.google.com/3.txt), Path.Combine(DataSource & strDirectory, "3.txt")) 
    End If 
If chk4.Checked Then 
     WC.DownloadFileAsync(New Uri("http://www.google.com/4.txt), Path.Combine(DataSource & strDirectory, "4.txt")) 
    End If 

我确实有一个跟踪下载的进度条,以及一个调用messagebox的已完成事件。

Private Sub WC_DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs) Handles WC.DownloadProgressChanged 
    ProgressBar1.Value = e.ProgressPercentage 

End Sub 
Private Sub WC_DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles WC.DownloadFileCompleted 
    MessageBox.Show("Download complete", "Download", MessageBoxButtons.OK, MessageBoxIcon.Information) 
End Sub 

我怎么能编程这下载所有文件检查? 我不介意用户是否只看到显示下载的文件或剩余时间的进度条,但是当所有下载完成时我都需要显示一些内容。

有什么建议吗?

回答

2

我认为是因为您使用单个WebClient实例同时执行多个HTTP请求。尝试使用几个实例。