本文實例講述了C#中WPF使用多線程調用窗體組件的方法。分享給大家供大家參考。具體如下:
Thread thread=new Thread(new ThreadStart(TestThread));thread.Start();private void TestThread(){ for (int i = 0; i < 11;i++ ) { Thread.Sleep(2000); this.listBox1.Dispatcher.Invoke(new Action(() => { this.listBox1.Items.Add("this is a test!!!"); })); }}
希望本文所述對大家的C#程序設計有所幫助。
新聞熱點
疑難解答