Resolved download file async with progressbar

Zexor

Well-known member
Joined
Nov 28, 2008
Messages
520
Programming Experience
3-5
I am trying to download file async and display it on a new tabpage and a progressbar in it. How do i refer to that progressbar so that i can increment it. and how do i refer to that tabpage to remove it once the download is done. Here is what i have so far.

VB.NET:
    Private Sub downloadFileAsync(sourceURL As String, destName As String)
        Dim _WebClient As New System.Net.WebClient()
        AddHandler _WebClient.DownloadFileCompleted, AddressOf downloadFileAsync_Completed
        AddHandler _WebClient.DownloadProgressChanged, AddressOf downloadFileAsync_ProgressChanged


        Dim tp As New TabPage
        tp.Text = destName.Substring(destName.LastIndexOf("\") + 1)
        tp.Name = tp.Text
        TabControl1.TabPages.Add(tp)


        Dim pb As New ProgressBar
        tp.Controls.Add(pb)


        _WebClient.DownloadFileAsync(New Uri(sourceURL), destName)
    End Sub


    Private Sub downloadFileAsync_ProgressChanged(sender As Object, e As DownloadProgressChangedEventArgs)
'send e.ProgressPercentage to progressbar
    End Sub


    Private Sub downloadFileAsync_Completed(sender As Object, e As System.ComponentModel.AsyncCompletedEventArgs)

'Remove tabpage when done

    End Sub
 
Last edited:
You can pass user information with the userToken parameter of DownloadFileAsync method, this information is available in UserState property of event info. Here needing the TabPage and the ProgressBar in that TabPage the common denominator of the informations you need is the TabPage reference, so you could pass that.
 
Back
Top