tmaifeld
asked on
Microsoft Background worker thread question
How does the background worker thread access an object class contained within a form? I thought a new thread started in it's own envirnoment. Example of the background worker thread given below. The code has a GUI component
Public Class BackgroundWorkerForm
Private emp1 As New Employee
Private Sub BackgroundWorker1_DoWork(B yVal sender As System.Object, _
ByVal e As System.ComponentModel.DoWo rkEventArg s) _
Handles BackgroundWorker1.DoWork
'Create a reference to the worker.
Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)
emp1.IdInteger = 5
End Sub
Private Sub startButton_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles startButton.Click
Me.BackgroundWorker1.RunWo rkerAsync( )
End Sub
Private Sub BackgroundWorker1_RunWorke rCompleted (ByVal sender As Object, _
ByVal e As System.ComponentModel.RunW orkerCompl etedEventA rgs) _
Handles BackgroundWorker1.RunWorke rCompleted
MessageBox.Show(emp1.IdInt eger())
End Sub
End Class
Public Class BackgroundWorkerForm
Private emp1 As New Employee
Private Sub BackgroundWorker1_DoWork(B
ByVal e As System.ComponentModel.DoWo
Handles BackgroundWorker1.DoWork
'Create a reference to the worker.
Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)
emp1.IdInteger = 5
End Sub
Private Sub startButton_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles startButton.Click
Me.BackgroundWorker1.RunWo
End Sub
Private Sub BackgroundWorker1_RunWorke
ByVal e As System.ComponentModel.RunW
Handles BackgroundWorker1.RunWorke
MessageBox.Show(emp1.IdInt
End Sub
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you can read as short article I wrote at http://www.emoreau.com/Entries/Articles/2006/12/The-BackgroundWorker-component.aspx