Have a look at the Progress Changed event
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.progresschanged.aspx[
^]
Within your DoWork method, you can call
ReportProgress[
^]
This will marshall across threads so you can update your UI progress bar with the new values. So
1) Create an event handler for your background worker ProgressChanged event
2) Within DoWork, periodically call
ReportProgress[
^], passing the percentage completed
3) In your event handler, update the progress bar with the new percentage
To tell it the progress has changed, add this code to your routine. It's YourBackgroundWorkerName.ReportProgress(value)
Try
MyObjSearcher = New System.Management.ManagementObjectSearcher(MyMgtScope.Path.ToString, _
"Select * FROM Win32_OperatingSystem")
MyColl = MyObjSearcher.Get
For Each MyObj In MyColl
OSNAME = (MyObj("caption").ToString())
StatusLabel.Text = "Getting Operating System"
If OSNAME = "Microsoft Windows 7 Enterprise " Then
OSNAME = "Windows 7"
ElseIf OSNAME = "Microsoft Windows 7 Ultimate " Then
OSNAME = "Windows 7 Ultimate"
ElseIf OSNAME = "Microsoft Windows XP Professional" Then
OSNAME = "Windows XP"
End If
Next
MachineBasic_BackgroundWorker.ReportProgress(10)
Catch ex As Exception
OSNAME = "UnKnown"
End Try
Just add lines like that throughout your DoWork routine and handle the event. So after that bit completes, in your next Try block add a line MachineBasic_BackgroundWorker.ReportProgress(20) ... etc etc