troubleshooting Question

Microsoft Background worker thread question

Avatar of tmaifeld
tmaifeld asked on
Visual Basic Classic
2 Comments1 Solution718 ViewsLast Modified:
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
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros