这样写就可以了this.comboBox1.Invoke(new Action(() => this.comboBox1.Items.Clear()));
解决方案 »
- 用C#编写网络通讯的的软件连接的原理是什么
- 我的visual studio 2008 为什么总出现这个问题? 高手帮助解决一下
- 关于图片向数据库的保存
- 捕获进程异常
- 高手帮忙,下面有一段调用API画框的函数,不知道怎么调的!
- mdiForm 最大化和关闭事件
- 请问如何将一组JPG图像文件转成AVI视频?谢谢
- 高分请教曾经遇到的一道笔试题!
- 在interface中不能定义属性吗?
- 在HTML(采用javasript)提交数据,如何用asp.net在第二个页面接受
- 求助,两个int数组之间的运算
- WPF中执行存储的结果是5个Table,每个Table一列,现在想把5个table分别绑定到5个Combox中,Binding怎么写怎样比较灵活
private void RunWithInvoke()
{
this.progressBar.Invoke(new Action(() =>
{
while (this.progressBar.Value < progressBar.Maximum)
{
this.progressBar.Value++;
//这句是干嘛用的,progressBar的值变化,comboBox1的项就清空?
this.comboBox1.Invoke(new Action(() => this.comboBox1.Items.Clear()));
Console.WriteLine(progressBar.Value.ToString());
}
}));
}
补加一个问题,假如要在
if (InvokeRequired)
{
//this.toolTip1.SetToolTip(comboBox1, "king");
}
中执行被注释的这行语句,该如何编写编码?this.toolTip1没有提供invoke()方法啊?
private void BindMethod()
{
this.toolTip1.SetToolTip(this.comboBox1, "");
} //调用
Thread th = new Thread(new ThreadStart(() =>
{
Bind bind = new Bind(BindMethod);
this.Invoke(bind);
}));
th.Start();
哦,谢谢,还有最后一个问题:
this.comboBox1.Invoke(new Action(() => this.comboBox1.Items.Clear()));
this.Invoke(new Action(() => this.comboBox1.Items.Clear()));这两行编码达到的效果是一样的,那它们有本质上的区别么?或者说编码时这两行编码随便选择之中一个都行!?
1、this.comboBox1指窗体上的comboBox1对象
2、this指窗体对象建议用第一种写法