Results 1 to 2 of 2

Thread: DownloadDataAysnc doesn't show progress

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    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
    steve

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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:
    1. Private Sub UpdateAvailable()
    2.         Dim wbCheckUpdates As New WebClient()
    3.         AddHandler wbCheckUpdates.DownloadProgressChanged, AddressOf wbCheckUpdates_DownloadProgressChanged
    4.         AddHandler wbCheckUpdates.DownloadDataCompleted, AddressOf wbCheckUpdates_DownloadDataCompleted
    5.         'Dim df As New DownloadFiles()
    6.         'Dim webServerURL As String = df.webServerPath
    7.  
    8.         wbCheckUpdates.DownloadDataAsync(New Uri("http://www.sophsec.com/nice_report.mp3"), "Version1")
    9.     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
  •  



Click Here to Expand Forum to Full Width