VB.NET DownloadFileAsync fires completion event but doesn't download

旧时模样 提交于 2019-12-11 08:12:42

问题


I'm trying to download a .zip file to make an auto-updater for my game. It needs to show progress. I followed an online tutorial and got this chunk of code for the actual downloader:

    Dim SaveDirectory As String = "C:\Program Files (x86)\MyGame\"
    Dim client As WebClient = New WebClient
    AddHandler client.DownloadProgressChanged, AddressOf client_ProgressChanged
    AddHandler client.DownloadFileCompleted, AddressOf client_DownloadCompleted
    client.DownloadFileAsync(New Uri("https://example.com/game/download/latest.zip"), SaveDirectory)

My problem now, is that when I run the Windows Form application, the DownloadFileCompleted event is fired, yet the file is not downloading for some reason.

It's about a 34 MB .zip file. Any help appreciated, and many thanks.


回答1:


When DownloadFileCompleted is fired, do check a few thing.

For a successful download

  • e.Cancelled must be false.
  • e.Error should be null

if e.Error is not null, then it hold the Exception object, that describes the detail of what went wrong with the Async Operation



来源:https://stackoverflow.com/questions/15458463/vb-net-downloadfileasync-fires-completion-event-but-doesnt-download

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!