DownloadFileAsync下载多个文件不完整
我要下载多个文件,在循环中的关键代码如下:
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 事件,问题是我在这个循环下载中怎么处理呢?恳请指教,非常感谢!!
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 事件,问题是我在这个循环下载中怎么处理呢?恳请指教,非常感谢!!
...全文
相关推荐
System.Net.FtpClient.Async:System.Net.FtpClient 的异步扩展
System.Net.FtpClient.Async System.Net.FtpClient 的异步扩展
C#webClient.DownloadFileAsync异步源码
//用于新手学习异步操作 //例子简单,下载字符串也是一个道理
C# Winform 下载文件
采用winform开发的下载文件的功能,使用WebClient中的DownloadFile方法
使用WebClient实现文件下载
使用WebClient实现文件下载,进度条反应下载进度。
WebClient上传下载文件
使用WebClient的UploadFileAsync、UploadFile、DownloadFile、DownloadFileAsync方法,异步调用服务器上传下载数据。


