winform 多线程改变UI控件状态

  new Thread(() => { 
            
                //多线程处理的任务
                //调用ui进程
                //Invoke(new Action(() => { 
                BeginInvoke(new Action(() => { 
                //改变UI控件状态
                
                }));
            
            }).Start();

比如:

 new Thread(() =>
                {

                    Thread.Sleep(1000);
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < 1000; i++)
                        sb.Append("test");
                    string s = sb.ToString();
                    Stopwatch sw = Stopwatch.StartNew();
                    Invoke(new Action(() =>
                    {
                        textBox1.Text = s;
                    }));
                    MessageBox.Show(sw.ElapsedMilliseconds.ToString());  



                }).Start();
上一篇:mysql5.7在centos上安装的完整教程以及相关的“坑”


下一篇:集群增量会话管理器——DeltaManager