t.Abort();可以終止一個(gè)線(xiàn)程
t.Suspend();可以?huà)炱鹨粋€(gè)線(xiàn)程
t.Resume();繼續已掛起的線(xiàn)程
進(jìn)程關(guān)閉:CloseMainWindow
Process[] ps = Process.GetProcessesByName( "進(jìn)程名 ");
foreach(Process myProcess in ps){
myProcess.CloseMainWindow();
}
首先,要把這個(gè)線(xiàn)程定義在函數外
比如
class A
{
Thread threadA;
private void Init()
{
//在這里實(shí)例化線(xiàn)程A
threadA = new Thread(new ThreadStart( dosomething ));
threadA.IsBackground = true; //這樣程序一退出線(xiàn)程就會(huì )自動(dòng)中止
threadA.Start();
}
private void Button1_Click(object sender, System.EventArgs e)
{
//這個(gè)是暫停按鈕的按下代碼
if( threadA != null )
{
threadA.Abort();
}
}
}
線(xiàn)程轉化的函數:
WaitSleepJoin------> Started
用Pulse,PulseAll,Interrupt
Running------------> WaitSleepJoin
用Wait,Sleep,Join
Running------------> Suspended
用Suspend
Suspended----------> UnStarted
用Resume
UnStarted----------> Started
用Start
threadA.IsBackground = true; //后臺線(xiàn)程
threadA.Abort();//終止 但不是一定管用
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請
點(diǎn)擊舉報。