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();