我需要在我的应用程序中下载一个大文件(大约3-5 5GB)。该文件是应请求动态生成的,因此我无法预测它何时可以下载。我需要尝试下载,当我得到404分时,我必须等待并稍后重试。
下载是异步的,因为我有一个进度条。我也试着放一个“普通”的下载(WC.DownloadFile(...))在try..catch中,但并没有解决我的问题。
Private Sub DownloadUpdate()
Dim RndName As String = IO.Path.GetRandomFileName
UpdateTmpPath = IO.Directory.CreateDirectory(IO.Path.Combine(IO.Path.GetTempPath, RndName)).FullName
UpdateTmpFile = UpdateTmpPath & "\update.zip"
UpdateUnzipDir = IO.Directory.CreateDirectory(UpdateTmpPath & "\update").FullName
Log(UpdateTmpFile)
WC.DownloadFileAsync(New Uri(url), UpdateTmpFile)
End Sub
顺便说一句,对不起我的英语,它不是我的第一语言:)
发布于 2019-02-14 04:25:19
找到答案:)通过添加处理程序"DownloadFileCompleted“,我可以检查Http状态:
Private Sub AfterDownload(ByVal sender As Object, ByVal e As Object) Handles WC.DownloadFileCompleted
Dim status As HttpStatusCode = DirectCast(CType(e.Error, WebException).Response, HttpWebResponse).StatusCode
If status = HttpStatusCode.NotFound Then
"...wait and retry download"
Else
"...do something with downloaded file"
End If
End Sub
希望这能帮助到别人。
丹尼尔
https://stackoverflow.com/questions/54639516
复制相似问题