这样写就可以了this.comboBox1.Invoke(new Action(() => this.comboBox1.Items.Clear()));

解决方案 »

  1.   

    代码也可简化一下        //使用Invoke方法来设置进度条 
            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());
                        }
                    }));
            }
      

  2.   

     if (InvokeRequired) 等价于 if (this.InvokeRequired) 
      

  3.   


    补加一个问题,假如要在
    if (InvokeRequired)
                    {
                        //this.toolTip1.SetToolTip(comboBox1, "king");
                    }
     中执行被注释的这行语句,该如何编写编码?this.toolTip1没有提供invoke()方法啊?
      

  4.   

    用代理        private delegate void Bind();
            private void BindMethod()
            {
                this.toolTip1.SetToolTip(this.comboBox1, "");
            }           //调用
                Thread th = new Thread(new ThreadStart(() =>
                    {
                        Bind bind = new Bind(BindMethod);
                        this.Invoke(bind);
                    }));
                th.Start();
      

  5.   


    哦,谢谢,还有最后一个问题:
               this.comboBox1.Invoke(new Action(() => this.comboBox1.Items.Clear()));
                        this.Invoke(new Action(() => this.comboBox1.Items.Clear()));这两行编码达到的效果是一样的,那它们有本质上的区别么?或者说编码时这两行编码随便选择之中一个都行!?
      

  6.   

    有区别
    1、this.comboBox1指窗体上的comboBox1对象
    2、this指窗体对象建议用第一种写法