Backgroundworker percentage not working
Hey everyone! Whats the problem with this code? My progressbar isnt changed during the worker async, it only messages me on the final, and downloads the file. Thanks!
Code:
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
My.Computer.Network.DownloadFile("http://fusioncountry.tk/OMSZ.rar", "E:\Rockstar Games\GTA San Andreas\SAMP\omsz.rar")
End Sub
Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
ProgressBar1.Value = e.ProgressPercentage
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
MessageBox.Show("Kész!")
End Sub
Re: Backgroundworker percentage not working
Of course it isn't changing. It's not going to happen on its own. You have to call ReportProgress if you expect the ProgressChanged event to be raised. Of course, how are you going to do that when there's no progress you can actually measure? Start by following the CodeBank link in my signature below and reading my thread about Using The BackgroundWorker. Then, realise that you can't report progress that you can't measure ands there's nothing to measure when you call that DownloadFile method. Next, get rid of all that code and look into using the WebClient class, which has built-in functionality to download asynchronously and report progress. Either that or use the overload of the DownloadFile method you're already calling that displays its own progress UI.
Re: Backgroundworker percentage not working
The DoWork event does not automatically raise the ProgressChanged event, because it cannot tell automatically what percentage of the work has been done so far... so you need to do it yourself.
In this case however you are just running one command, so there isn't a way to work out the percentage done so far (just 0% before it runs, and 100% after).
In order to get a progressbar to work with downloading a file, you will need to use a downloading method that reports progress.
Re: Backgroundworker percentage not working
Oh okay, I understand you, but can somebody link me webclient class usage please? I didnt used it before.
Re: Backgroundworker percentage not working
Ahhh... you can find it yourself just as easily... goto to google .... and type in vb.net webclient class and press enter. That's how you find anything new when you come across it. It's how I do it. It's probably how most of us do it. I don't think any of us just have these links ready to go... MS is always moving things around and re-arranging where stuff is, so it's easier to look it up on google (or bing, or yahoo, or if you're feeling really goosey loosey DuckDuckGo).
-tg
Re: Backgroundworker percentage not working
Quote:
Originally Posted by
Daveeed
can somebody link me webclient class usage please?
Wow, it's quite a coincidence that neither Google nor the Help menu in VS are working for you at the same time. That's a tough break. Seriously though, you don't need us to provide a link to something you can find in seconds for yourself by simply using the documentation built into VS or a search engine. You may think we have unlimited time but it sure would help if you did your own web searches.
Re: Backgroundworker percentage not working
Thank you guys! I resolved it, thanks for help!