I am having problem to show the Data arrived from System.Net.Sockets onto textbox
'Cross-thread operation not valid: Control 'txtDataRx' accessed from a thread other than the thread it was created on'
Code:
public void ReceiveSckData(IAsyncResult aData)
{
try
{
CSocketPacket theSockId = (CSocketPacket)aData.AsyncState;
//end receive...
int iRx = 0;
iRx = theSockId.thisSocket.EndReceive(aData);
char[] chars = new char[iRx + 1];
System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
int charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0);
System.String szData = new System.String(chars);
//MessageBox.Show(theSockId.dataBuffer.Length.ToString());
MessageBox.Show(szData);
txtDataRx.Text = szData; // I AM GETTING ERROR HERE
}
catch (ObjectDisposedException)
{
System.Diagnostics.Debugger.Log(0, "1", "\nOnDataReceived: Socket has been closed\n");
}
catch (SocketException se)
{
MessageBox.Show(se.Message);
}
}