所以我正在一个程序中下载一个工作良好的文件直到2天前(我有一个本地git我也将代码返回到1周但仍然无法工作)
代码来自互联网上的教程
Private WithEvents Downloader As New WebClient
Private Sub Downloader_DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs) Handles Downloader.DownloadProgressChanged
Dim bytesIn As Double = Double.Parse(e.BytesReceived.ToString())
Dim totalBytes As Double = Double.Parse(e.TotalBytesToReceive.ToString())
Dim percentage As Double = bytesIn / totalBytes * 100
totalBytes = totalBytes / 1024
Label1.Text = String.Format("{0:0}%", percentage)
Dim kbps As Double = e.BytesReceived / 1024
If kbps < 1024 Then
lblMessage.Text = String.Format("Downloading: {0:0.00} KB", kbps) & " " & String.Format("/ {0:0.00} MB", totalBytes / 1024)
Else
lblMessage.Text = String.Format("Downloading: {0:0.00} MB", kbps / 1024) & " " & String.Format("/ {0:0.00} MB", totalBytes / 1024)
End If
End Sub
Private Sub Downloaded()
'stuff after it finish
End Sub
' the button calls this
Private Sub DownloadFiles()
Try 'to download the patch
AddHandler Downloader.DownloadFileCompleted, AddressOf Downloaded
AddHandler Downloader.DownloadProgressChanged, AddressOf Downloader_DownloadProgressChanged
Downloader.DownloadFileAsync(New Uri("http://mytop100.eu/system.zip"), My.Computer.FileSystem.CurrentDirectory & "\system.zip")
Catch ex As Exception
lblMessage.Text = ex.Message
End Try
End Sub
在我尝试调试情况后,我得出的结论是
e.TotalBytesToReceive
总是返回-1,但是当下载完成时它会显示正确的文件大小数量,所以我去了https://www.thinkbroadband.com/download并且我添加了链接这个http://ipv4.download.thinkbroadband.com/10MB.zip并且它工作正常所以我的webhost有错误?我的档案?或者我在代码中遗漏了什么?
这是下载开始时视觉问题的照片http://prntscr.com/gt0gx5
完成时http://prntscr.com/gt0h7v