如何等到 vb.net 中不再有来自 webclient 的“404”?

How to wait until no more "404" is coming from weblient in vb.net?

我需要在我的应用程序中下载一个大文件(大约 3-5GB)。该文件是根据请求动态生成的,所以我无法预测何时可以下载。我需要尝试下载,当我收到 404 时,我必须等待并稍后重试。

下载是异步的,因为我有一个进度条。 我也尝试将 "normal" 下载 (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

顺便说一句,对不起我的英语,这不是我的第一语言:)

找到答案:) 通过添加处理程序 "DownloadFileCompleted" 我可以检查 Http-Status:

    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

希望对大家有所帮助。

丹尼尔