2010年12月23日 星期四

Async File Downloader

Private Sub DownloadFile(ByVal fileToDownload As String, ByVal savePath As String)
Dim webClient As New WebClient()
AddHandler webClient.DownloadFileCompleted, AddressOf Completed AddHandler webClient.DownloadProgressChanged, AddressOf ProgressChanged
webClient.DownloadFileAsync(New Uri(fileToDownload), savePath)
End Sub

Private Sub ProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
Progressbar1.Value = e.ProgressPercentage
End Sub

Private Sub Completed(ByVal sender As Object, ByVal e As AsyncCompletedEventArgs)
MessageBox.Show("Finished!", "File complete!", MessageBoxButtons.OK, MessageBoxIcon.Information)
Progressbar1.Value = 0
End Sub

沒有留言:

張貼留言