You are updating a UI control from a different thread.
instead of updating it directly,
txtDataRx.Text = txtDataRx.Text + szData;
instead use a delegate,
e.g define a delegate
delegate void UpdateTextBoxCallBack(TextBox txtBox, string strText);
create a method, to update this text box as shown below.
public void UpdateTextBox (TextBox txtBox, string strText)
{
if (txtBox.InvokeRequired)
{
UpdateTextBoxCallBack upcb = new UpdateTextBoxCallBack(UpdateTextBox);
this.Invoke(upcb, new object[] { txtBox, strText});
}
else
{
txtBox.Text = strText ;
}
}
and when you need to update this text box from some other thread. just call the method
UpdateTextBox (txtBox, "New Text to be updated" );
hope this helps.
-praveen.