Delegates And Cross Thread Exception

Posted by Neo on Stack Overflow See other posts from Stack Overflow or by Neo
Published on 2010-04-20T06:25:58Z Indexed on 2010/04/20 7:13 UTC
Read the original article Hit count: 234

Whenever i am updating UI in windows form using delegate it gives me cross thread exception why it is happening like this? is there new thread started for each delegate call ?

void Port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
//this call delegate to display data
clsConnect(statusMsg);
}

protected void displayResponse(string resp)
{
//here cross thread exception occur if directly set to lblMsgResp.Text="Test";
if (lblMsgResp.InvokeRequired)
{
lblMsgResp.Invoke(new MethodInvoker(delegate { lblMsgResp.Text = resp;
})); }
}

© Stack Overflow or respective owner

Related posts about delegates

Related posts about c#