0
您好我在做一個vb.net更新功能,讓我的用戶的通知,當有新的更新可供下載Vb.net WebClient.DownloadFileAsync在XP不會工作和8.1
所以它贏的所有作品8和7,但是當我嘗試在XP和8.1運行它,它只是提供了一個下載完成,但不下載任何文件:■
這裏是我的代碼:
Imports System.Net
Public Class Form5
Private Sub LogInButton1_Click(sender As Object, e As EventArgs) Handles LogInButton1.Click
Dim client As WebClient = New WebClient
AddHandler client.DownloadProgressChanged, AddressOf client_ProgressChanged
AddHandler client.DownloadFileCompleted, AddressOf client_DownloadCompleted
client.DownloadFileAsync(New Uri("FILE the download"), "C:\users\" & System.Environment.UserName & _
"\AppData\Local\Software_update.exe")
LogInButton1.Text = "Download in Progress"
LogInButton1.Enabled = False
End Sub
Private Sub client_ProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
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
LogInProgressBar1.Value = Int32.Parse(Math.Truncate(percentage).ToString())
End Sub
Private Sub client_DownloadCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
MessageBox.Show("Download Complete please restart the app ")
LogInButton1.Text = "Download Complete"
End Sub
Private Sub Form5_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
Form1.Close()
End Sub
End Class
注意我力又上測試該Vista
幾乎可以肯定的異常被拋出d
。該異常通過'DownloadCompleted'事件處理程序中的'e.Error'屬性提供給您。看看它,它會告訴你出了什麼問題。你真的應該知道這一點,因爲你應該閱讀'WebClient'類的文檔和你正在使用的成員。 – jmcilhinney 2014-09-30 00:02:04