MyXBeeDevice.Transmit
(1)
TextBoxSend.Focus
(1)
ReceivedData.Length
(1)
XBeeDevice
(1)
ReceivedData
(1)
ButtonSend
(1)
EventArgs
(1)
TextBox
(1)

Chat Application with TextBox

Asked By Gonzalo
10-Nov-09 10:20 PM
Hi all,

I have a chat application in Windows CE 6.0 with 2 TextBox, one TextBox to
write the frame to send an the other one to write the frames sent and
received.

When I  send a frame, I write it in the TextBox.

private void ButtonSend_Click(object sender, EventArgs e)
{
if (TextBoxSend.Text != "")
MyXBeeDevice.Transmit(TextBoxSend.Text);
TextBoxLog.Text += "-> " + TextBoxSend.Text + "\r\n";
TextBoxSend.Text = "";
TextBoxSend.Focus();
}

However, when I receive a frame, I cannot write it in the TextBox, I have an
Exception.

private void PacketReceived(XBeeDevice sender, byte[] ReceivedData)
{
TextBoxLog.Text += "<- " +
InternalEncoding.GetString(ReceivedData, 0, (int)ReceivedData.Length) +
}

I have tried write a string in the TextBox e.g.("Hello World") and I have
the same Exception. Does anyone know what is the problem?

Thank you .

You cannot asynchronously perform operations to GUI objects.

Paul G. Tobey [eMVP] replied to Gonzalo
11-Nov-09 12:07 AM
You cannot asynchronously perform operations to GUI objects.  The button
click is NOT asynchronous, because a user interface operation, the click,
triggered the event.  However, it should be clear that a serial port event
is totally asynchronous with the GUI, so you have to use Invoke() to do
anything to a control, window, etc. from the serial event handler.

Paul T.
Post Question To EggHeadCafe