winform程序一般是不允许非主线程操作ui,单可以通过线程与委托的方式并结合Control类提供的BeginInvoke机制进行ui更改

如下,这是更新ui的方法

 

private void upUiMethod()
{
    .....
}

1:创建委托

  private delegate void delegateUpUI();

  private delegateUpUI delUpUI;

2:给委托添加方法

delUpUI+=upUiMethod;

3:创建invoke方法

 public void upUiInvoke()
 {
     while (!this.IsHandleCreated)
     {
         Thread.Sleep(200);
     }
     this.BeginInvoke(delUpUI);
  }    

4.创建线程

Thread thred = new Thread(new ThreadStart(upUiInvoke)); 
thred.IsBackground
= true;
thredI.Start();

 

相关文章:

  • 2022-02-09
  • 2022-12-23
  • 2021-11-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-23
猜你喜欢
  • 2022-12-23
  • 2021-07-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-10
  • 2021-08-24
相关资源
相似解决方案