| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 889 人关注过本帖
标题:cross-threading错误的解决方法?
只看楼主 加入收藏
swc
Rank: 3Rank: 3
等 级:论坛游民
威 望:6
帖 子:394
专家分:83
注 册:2006-4-7
结帖率:100%
收藏
 问题点数:0 回复次数:1 
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
chenjin145
Rank: 1
等 级:禁止访问
帖 子:3922
专家分:0
注 册:2006-7-12
收藏
得分:0 
this.Invoke(d, new object[] { text,e });

簽名,參數必須一致

[url=javascript:alert(1);] [div]fdgfdgfdg\" on\"[/div] [/url]
2006-08-10 09:03
快速回复:cross-threading错误的解决方法?
数据加载中...
 
   



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

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