为什么 再构造函数里启动一个线程更新UI不报错 ,但是在 例如一个按钮事件里面启动线程更新UI报错???

解决方案 »

  1.   

    http://www.cnblogs.com/wizardh/articles/963097.html
      

  2.   

    每个进程至少都有一个主线程,在Winform中,应该就是创建GUI的线程
      

  3.   

    this.TextBox.Invoke(new MethodInvoker(delegate(){
         your code
    }));
      

  4.   

    次线程不能直接更新UI的控件内容,可以利用委托的方式来达到更新的目的,比如定义一个方法:
      private void AddItemValue(RichTextBox listView, String message)
     {
                listView.AppendText(message + "\r");
                listView.ScrollToEnd();
      }在次线程中更新RichTextBox控件的值就可以这样写:
    txtRich.Dispatcher.Invoke(DispatcherPriority.Background, new SetItemView(AddItemValue), txtRich,"Hello World");