Webclient download progress?

robplatt

Freshman
Joined
Jul 14, 2006
Messages
39
I know (and have the code) to use webclient async to start a file download, then put code in the progress function to watch the status. Works fine, but its more like a background thread while the rest of your app continues to run...

However, I need or would like the abililty to do the same thing only not async. In other words I want to start a download, watch the progress bar and then move on to the next lines of code.

I suppose I could watch for when the download finished and then have my code there, but im downloading a few things. and i dont want to have to put it in a seperate form. I would like to:

1; download file a
2; watch progress
3; process file a
4; download file b
5; process file b
6; finish.

any ideas? anyone else do something similar?
 
You might find it easier to download the data in question as a stream (using the .OpenRead method) - this will allow you do download it in chunks and do any relevant status updates in between chunks.
 
I can use that in a for...next huh, ill have to play around with it. if i figure it out ill post it for others.
 
PlausibyDump... I am ashamed at you :p Your an expert you should have suggested the most obvious :D didnt dawn on me until just now, so i hang my head low. some programmer i am.

This works exactly as i wanted it:

Visual Basic:
 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Show()
        WebClient.DownloadStringAsync(New Uri("www.whatever"))
        While WebClient.IsBusy
            Application.DoEvents()
        End While

    End Sub

    Private Sub webClient_DownloadProgressChanged(ByVal sender As System.Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles WebClient.DownloadProgressChanged
        ProgressBar1.Value = e.ProgressPercentage
    End Sub


But I do thank you for your response. I learned a few things on my quest for this answer.
 
Last edited:
Back
Top