|
-
Aug 1st, 2009, 10:12 PM
#1
Thread Starter
Frenzied Member
DownloadDataAysnc doesn't show progress
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
-
Aug 2nd, 2009, 03:34 AM
#2
Re: DownloadDataAysnc doesn't show progress
Tried your code, works fine. The only thing I can think of is that the txt file you're downloading isn't big enough nor was the 'big' file that you tried. I decided to try it with a large file, so I used one which I found recently on the Pwnie Awards website.
Try this:
vb 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("http://www.sophsec.com/nice_report.mp3"), "Version1") End Sub
The song is awful though, don't listen to it. Also make sure that the progressbar's maximum value has been set to 100.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|