Hello,
VS 2008 SP1
I am using the DownloadDataAysnc. But the ProgressChanged event doesn't show progress until after the data has been downloaded.
Even when I try and download a data which is contained in a big file. The programs remains responsive so I know it is doing something. However, it is when the progress has completed that the progressChanged event fires.
I known this as the progressChanged and the DownloadDataCompleted fire immediately after each other. However, they should be a pause as the file is quite big.
This is the code snippet I am currently using. And the output below. What is strange the e.progresspercentage is 100%. And seems to get called twice.
Many thanks for any advise,
Results:
Progress changed Version userstate: [ Version1 ]
progressBar1.Value [ 100 ]
Progress changed Version userstate: [ Version1 ]
progressBar1.Value [ 100 ]
Completed data: [ 1.0.11 ]
Code:Private Sub UpdateAvailable() Dim wbCheckUpdates As New WebClient() AddHandler wbCheckUpdates.DownloadProgressChanged, AddressOf wbCheckUpdates_DownloadProgressChanged AddHandler wbCheckUpdates.DownloadDataCompleted, AddressOf wbCheckUpdates_DownloadDataCompleted Dim df As New DownloadFiles() Dim webServerURL As String = df.webServerPath wbCheckUpdates.DownloadDataAsync(New Uri(Path.Combine(webServerURL, "version.txt")), "Version1") End Sub Private Sub wbCheckUpdates_DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs) Console.WriteLine("Progress version changed userstate: [ " & e.UserState & " ]") progressBar1.Value = e.ProgressPercentage Console.WriteLine("progressBar1.Value [ " & Me.progressBar1.Value & " ]") End Sub Private Sub wbCheckUpdates_DownloadDataCompleted(ByVal sender As Object, ByVal e As DownloadDataCompletedEventArgs) Dim result As Byte() = e.Result Console.WriteLine("Completed data: [ " & System.Text.ASCIIEncoding.[Default].GetString(result) & " ]") End Sub




Reply With Quote