Imports System.Net
Public Class DownloadStuff
Dim downloader As New WebClient()
Private Sub Progress_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Progress.Validated
AddHandler downloader.DownloadProgressChanged, AddressOf DownloadChangedHandler
Dim uri As New Uri("http://www.example.com/example.txt")
downloader.DownloadFileAsync(uri, "C:\example.txt")
End Sub
Private Sub DownloadChangedHandler(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
Progress.Maximum = CInt(e.TotalBytesToReceive)
Progress.Value = CInt(e.BytesReceived)
Application.DoEvents()
End Sub
End Class
This is my code, but the DownloadProgressChanged event is NEVER fired. (I am using an example URL here, but it is the same basic stuff)
What am I doing wrong? Progress is a ProgressBar.
This is in VB.net.
On MSDN, they mentioned something about overriding GetWebRequest, but I have no idea how to do that or what to do.
UPDATE: Still no progress, I simply cannot figure out how to make the handler fire.