我在另外的线程上调用ocx控件的方法,当这个方法执行的时候,ui线程不能动了,这是怎么回事?怎么解决这个问题?

解决方案 »

  1.   

    不要在创建控件以外的线程操作控件,一直以来都有这么一个约定,不知道为什么很难找到,.Net 2.0已经把这个作为异常了。可以使用Control的Invoke方法,将操作放到UI线程上。
      

  2.   

    忘给例子了
    private void Form1_Load(object sender, System.EventArgs e)
    {
        System.Threading.Thread tNew = new System.Threading.Thread    (new     System.Threading.ThreadStart(this.Test));
        tNew.Start();
    }delegate void SetVisibleDelegate();private void SetVisible()
    {
       this.button1.Visible = true;
    }private void Test()
    {
       this.Invoke(new SetVisibleDelegate(SetVisible));
    }