DownloadFileAsync下载多个文件不完整

tangzhong tangzhong 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我要下载多个文件,在循环中的关键代码如下:

Dim myWebClient As New WebClient()
If myWebClient.IsBusy Then
myWebClient.CancelAsync()
End If

Dim remoteUri As String = strOldPath
If myWebClient.IsBusy Then
myWebClient.CancelAsync()
End If
TxtBoxLog.Text = "正在下载:" + strOldPath & vbCrLf & TxtBoxLog.Text

Dim uri As New Uri(remoteUri)
myWebClient.DownloadFileAsync(New Uri(strOldPath), strNewPath)
myWebClient.Dispose()
myWebClient = Nothing
TxtBoxLog.Text = "完成下载:" + strOldPath & vbCrLf & TxtBoxLog.Text

我发现下载文件还是非常快的,问题是有些文件没下载完成,有些只有一半,还有一些是0字节,不知道什么原因,恳请指教。

我在网上看到有说绑定 DownloadDataCompleted 事件,问题是我在这个循环下载中怎么处理呢?恳请指教,非常感谢!!

...全文
评论 17
收藏 已收藏
分享
返回顶部
tangzhong
VB 16,718 成员 110,520 内容