我有一個按鈕,其中包含十個方法。在這裏,我想使用按鈕點擊或代碼中的某些地方的線程,以便我的Windows窗體應用程序不會掛起。關於c中的線程#
這是我迄今嘗試過的...... !!
collectListOfPTags();
REqDocCheck = new Thread(new ThreadStart(collectListOfPTags));
REqDocCheck.IsBackground = true;
REqDocCheck.Start();
WaitHandle[] AWait = new WaitHandle[] { new AutoResetEvent(false) };
while (REqDocCheck.IsAlive)
{
WaitHandle.WaitAny(AWait, 50, false);
System.Windows.Forms.Application.DoEvents();
}
在collectionListOfPtags()
我得到一個異常,說的方法「的組合框從其它線程訪問比它是在創建」
感謝對耐心.. 任何幫助將不勝感激..
有一個很好的介紹到這裏螺紋:['Albahari'(http://www.albahari.com/threading/) – 2013-04-05 11:22:51
您不能訪問一個GUI從主線程以外的其他線程進行控制。有關於SO的19861353帖子關於那個...搜索它(http://stackoverflow.com/search?q=gui+thread) – derape 2013-04-05 11:24:03
@NicholasButler我已經經歷了那個..!感謝您的回覆 – 2013-04-05 11:24:26