您的位置:首页 > 其它

线程间操作无效: 从不是创建控件的线程访问它

2011-07-05 22:30 267 查看
解决方法一:
updateScollText = new System.Threading.Thread(new System.Threading.ThreadStart(ScrollText));
//加这句
Control.CheckForIllegalCrossThreadCalls = false;
updateScollText.Start();

解决方法二:
//先做如下函数声明
// This delegate enables asynchronous calls for setting
// the text property on a TextBox control.
delegate void SetTextCallback(TextBox textBoxTemp, string text);
private void SetText(TextBox textBoxTemp, string text)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (textBoxTemp.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object[] { textBoxTemp, text });
}
else
{
textBoxTemp.Text = text;
}
}
//在进程中显示信息时,使用如下命令:
SetText(tb_ServerExceptionCount, m_socketServer.ServerExceptionCount.ToString());

解决方法三:
使用backgroundWorker控件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐