First, define an instance variable for your main form in your thread class:
Private m_MainForm as MyMainFormClass
When you create your thread, pass in the main form instance and store in
m_MainForm. Now your thread has an instance to communicate with.
Next, define a delegate in your thread class:
Private Delegate Sub _SendString_Delegate(ByVal theString As String)
Also, create a method in your thread class for sending a string to the main
thread:
Public Sub SendString(ByVal theLabel As String)
Dim Parameters(0) As Object
Parameters(0) = theString
Try
m_MainForm.Invoke(New _SendString_Delegate(AddressOf
m_MainForm.DisplayText), Parameters)
Catch ex As Exception
End Try
End Sub
Execute this method in your thread whenever you wish to send a string
Finally, in your main form, add a method "DisplayText(byval theString as
String)".
"C.A." <nospam> wrote in message
news:OU**************@TK2MSFTNGP15.phx.gbl...
I am looking at the Creating a Multi-User TCP Chat Application
and I do not understand something. They say that we cannot
directly add the received text to the textbox of the client because
the receiving thread from the network stream is not the main thread.
The solution offered is to use the me.invoke method to switch to
the main thread, i.e.
Me.Invoke(New DisplayInvoker(AddressOf Me.DisplayText), params)
I can't see how this switches back to the main thread, Me refers to
the current instance, which is not the main thread,
AddressOf Me.DisplayText is the address of DisplayText in the current
thread ?