I wrote a tcpClient that speaks to a server over a telnet connection.
The code below sends a packet (in this case, an authentication packet to login), and then does an asynchronus read to the callback.
Public Sub SendPacket(ByRef Packet As AMIPacket)
Dim myWriteBuffer As NetworkStream = _session.GetStream
If myWriteBuffer.CanWrite Then
myWriteBuffer.BeginWrite(Packet.RenderPacket, 0, Packet.RenderPacket.Length, callBack, myWriteBuffer)
The problem is: the function that executes the asychnous operation parses the return information, which I need to pass to a textbox control on the form so I can log the communications. I get the error:
Cross-thread operation not valid: Control 'txtLog' accessed from a thread other than the thread it was created on.
A first chance exception of type 'System.InvalidOperationEx
ception' occurred in System.Windows.Forms.dll
How do I get the parsed data that is returned from the server passed to the form?