【问题标题】:VB - Using DownloadFileASync (WebClient) for multiple downloadsVB - 使用 DownloadFileASync (WebClient) 进行多次下载
【发布时间】:2011-10-28 15:19:52
【问题描述】:

我正在尝试根据用户在表单上选择的内容下载多个文件。 我有多个复选框,所以如果用户选择复选框 1、3、4,我希望网络客户端下载文件 1.txt、3.txt、4.txt。 WebClient 方法导致“WebClient 不支持并发 I/O 操作”。错误。

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

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

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

我该如何进行编程以下载所有检查过的文件? 我不介意用户是否只看到显示已下载文件总数或剩余时间的进度条,但我确实需要在所有下载完成时显示一些内容。

有什么建议吗?

【问题讨论】:

    标签: vb.net webclient downloadfileasync


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多