Link to home
Start Free TrialLog in
Avatar of tmaifeld
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(ByVal sender As System.Object, _
      ByVal e As System.ComponentModel.DoWorkEventArgs) _
      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.RunWorkerAsync()
    End Sub

    Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, _
      ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) _
      Handles BackgroundWorker1.RunWorkerCompleted

        MessageBox.Show(emp1.IdInteger())
      End Sub
End Class
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial