问题
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.Cancelledmust be false.e.Errorshould 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