I have a System.ComponentModel.BackgroundWorker component (BackGroundClientWait) within a class(myClass) that raises an event (message). My class is declared on a form (myForm) which contains a textbox (txtMessages). When I handle the event (message) and write the passed value (ByVal value as string) to the txtMessages textbox I get "Cross-thread operation not valid: Control 'txtMessages' accessed from a thread other than the thread it was created on.". I don't understand why this is happening because I am not accessing the txtMessages from another thread, just responding to an event from another thread. Any idea? Thanks in advance.
Public Class clsMyClasss
Dim WithEvents BackGroundClientWait As System.ComponentModel.BackgroundWorker = New System.ComponentModel.BackgroundWorker
Private Sub BackGroundClientWait_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackGroundClientWait.DoWork
RaiseEvent Message("Client: Received " & myString.Trim)
End Sub
End Class
Private Sub myClass_Message(ByVal value As String) Handles myClass.Message
txtMessages.Text = txtMessages.Text & value & vbCrLf
End Sub
System.InvalidOperationException
{"Cross-thread operation not valid: Control 'txtMessages' accessed from a thread other than the thread it was created on."}
Public Class clsMyClasss
Dim WithEvents BackGroundClientWait As System.ComponentModel.BackgroundWorker = New System.ComponentModel.BackgroundWorker
Private Sub BackGroundClientWait_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackGroundClientWait.DoWork
RaiseEvent Message("Client: Received " & myString.Trim)
End Sub
End Class
Private Sub myClass_Message(ByVal value As String) Handles myClass.Message
txtMessages.Text = txtMessages.Text & value & vbCrLf
End Sub
System.InvalidOperationException
{"Cross-thread operation not valid: Control 'txtMessages' accessed from a thread other than the thread it was created on."}