I was hoping for some help with my backgroundworker as I just cant get it to work. Basically I have a backgroundworker which does a few tasks but I’m trying to implement a progress bar and a label. I’m going to set the maximum value of the progress bar to 10 and then have it updating as I move with each task, also I’m thinking of a label with the progress bar which will display the progress ie
Pb value = 2
20% completed
Pb value = 6
60% completed
and so on.
So far I have this for the coding.
Update* Thanks lars fr your help.
So just a quick question would the do work event be like so?
Private Sub BGWorker_DoWork(ByVal sender As Object, _
ByVal e As DoWorkEventArgs) _
Handles BGWorker.DoWork
For i as Integer = 1 to 2
'My task code 1
BGWorker.ReportProgress(i)
Next
For i as Integer = 3 to 4
'My task code 2
BGWorker.ReportProgress(i)
Next
For i as Integer = 5 to 6
'My task code 3
BGWorker.ReportProgress(i)
Next
For i as Integer = 7 to 8
'My task code 4
BGWorker.ReportProgress(i)
Next
For i as Integer = 9 to 10
'My task code 5
BGWorker.ReportProgress(i)
Next
End Sub
Instead of trying to set the progress bar value in
DoWork(which isn’t running on the UI thread), you need to have the BackGroundWorker “report” it’s progress:Then in your
ProgressChangedevent, you can set the value of the Progress bar: