标题:cross-threading错误的解决方法?
取消只看楼主
swc
Rank: 3Rank: 3
等 级:论坛游民
威 望:6
帖 子:394
专家分:83
注 册:2006-4-7
结帖率:100%
 问题点数:0 回复次数:0 
cross-threading错误的解决方法?
msdn中有这么一种解决方法,但很不实用,想通过修改来扩大其适应性,但出错了.哪位大侠解释解释?
delegate void SetTextCallback(string text);
private void SetText7(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 (this.label7.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText7);
this.Invoke(d, new object[] { text });
}
else
{
this.label7.Text = text;
}
}

尝试着改为:
delegate void SetTextCallback(string text,Label e);
private void SetText(string text,Label e)
{
// 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 (e.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object[] { text });
}
else
{
e.Text = text;
}
}
SetText(text,label1);//调试时出错.
搜索更多相关主题的帖子: thread void string text delegate 
2006-08-09 19:41



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-83076-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.777028 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved