需要注意的是,必須從UI線程,另外啟動一個線程才可以。
在新線程調用異步刷新就OK了
Thread thread;
private void button1_Click(object sender, EventArgs e) { thread = new Thread(new ThreadStart(AnotherRefresh)); thread.IsBackground = true; thread.Start(); } private void AnotherRefresh() { MyRefresh("hello world"); Thread.Sleep(1000); MyRefresh("Bye Bye"); } private void MyRefresh(string str) { try { this.Invoke((MethodInvoker)delegate() { textBox1.Text = str; }); } catch (Exception ex) { MessageBox.Show(ex.Message); } }