2
我有一個線程可以打開一個MyMessageAlert類型的表單。 此表單是一個彈出窗口,當我打電話時它會打開。 它有一個計時器,在30秒後調用方法CloseWindow()。如何殺死C#中的線程?
m_messagAlert = new MyMessageAlert();
ParameterizedThreadStart thStart = new ParameterizedThreadStart(m_messagAlert.setMessage);
Thread thread = new Thread(thStart);
thread.Start(strMessage); //at this point, the MyMessageAlert form is opened.
我已經定義類型線程的列表:
public List<Thread> m_listThread;
每當我創建一個線程的時候,我把它添加到我的清單:
m_listThread.Add(thread);
當我關閉應用程序,我希望打開的MyMessageAlert類型的表單將立即關閉(不等待30秒)。 問題是,我不能讓它停止!
我試圖去在名單使用中止()函數的循環殺死它:
foreach (Thread thread in m_listThread)
{
if (thread.IsAlive)
thread.Abort();
}
但它並不能幫助。
嗨,它工作!我們剛剛添加了命令 thread.IsBackground = true; – 2011-01-24 11:49:42