首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

[急].net3.0中的跨线程控件访问解决方法

2012-01-29 
[急].net3.0中的跨线程控件访问关于.net3.0中的跨线程控件访问:在.net2.0中我们可以将Control.CheckForIll

[急].net3.0中的跨线程控件访问
关于.net3.0中的跨线程控件访问:
在.net2.0中我们可以将   Control.CheckForIllegalCrossThreadCalls   设置为false   或使用控件的Invoke等方法来实现,那么.net3.0中应该怎么实现呢?
谢谢

[解决办法]
3.0中设置子线程不可以么?2.0里都是用Invoike来做的
[解决办法]
用委托啊
public delegate void ShowInformation(string str);//显示信息
/// <summary>
/// 显示信息
/// </summary>
void ShowInfo(string StrInfo)
{
Invoke(new ShowInformation(OnshowInformation), StrInfo);
}
void OnshowInformation(string StrInfo)
{
lblInfo.Text = StrInfo;
}

这个应该和3.0没有什么关系的啊。
[解决办法]
学习
[解决办法]
用委托
[解决办法]
都3.0啦
[解决办法]
3.0不能Invoke了?
[解决办法]
把Control.CheckForIllegalCrossThreadCalls设置成false不好!

这个问题在2.0中应该就有了,而且MSDN上有例子。

在访问控件的时候要先判断 Control.InvokeRequire,如果true就Invoke委托,false就执行你要执行操作。

来个例子吧:

private delegate ListViewItem DelegateFindListItemByIdentifier(ListView lv, string sIdentifier);

private ListViewItem FindListItemByIdentifier(ListView lv, string sIdentifier)
{
if (lv.InvokeRequired)
{
DelegateFindListItemByIdentifier d = new DelegateFindListItemByIdentifier(FindListItemByIdentifier);
return Invoke(d, new object[] {lv, sIdentifier}) as ListViewItem;
}
else
{
foreach (ListViewItem item in lv.Items)
{
if ((string) item.Tag == sIdentifier)
{
return item;
}
}
return null;
}
}
[解决办法]
我这还停留在1.1呢,连2.0都没尝试过呢,楼主这都3.0啦,天啊~~~~
[解决办法]
http://www.cnblogs.com/zhouyinhui/archive/2007/05/10/742134.html


这里有标准答案

热点排行