线程间操作无效: 从不是创建控件的线程访问它
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控件
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控件
相关文章推荐
- 黑马程序员-线程间操作无效: 从不是创建控件“txtbox1”的线程访问它。
- 线程间操作无效: 从不是创建控件的线程访问它
- 线程间操作无效: 从不是创建控件“textBox1”的线程访问它
- 线程间操作无效: 从不是创建控件“progressBar1”的线程访问它
- 线程间操作无效: 从不是创建控件的线程访问它
- 线程间操作无效:从不是创建控件的线程访问它的三种方法
- 线程间操作无效: 从不是创建控件的线程访问它。
- C#线程间操作无效: 从不是创建控件“dataGridView1”的线程访问它
- 线程间操作无效: 从不是创建控件的线程访问它
- 线程间操作无效:从不是创建控件“......” 的线程访问它
- 线程间操作无效: 从不是创建控件“”的线程访问它~~~的解决方法~
- 转:线程间操作无效: 从不是创建控件“”的线程访问它~~~的解决方法~
- “线程间操作无效: 从不是创建控件的线程访问它”
- 线程间操作无效: 从不是创建控件“xxxxxxxx”的线程访问它。
- 小结“线程间操作无效: 从不是创建控件的线程访问它” 错误的解决方法
- 线程间操作无效: 从不是创建控件“Control Name'”的线程访问它问题的解决方案及原理分析
- 线程间操作无效: 从不是创建控件“...”的线程访问它。
- “线程间操作无效: 从不是创建控件的线程访问它”
- 线程间操作无效:从不是创建控件的线程访问它的三种方法
- 线程间操作无效:从不是创建控件“XX”的线程访问它