111,129
社区成员
发帖
与我相关
我的任务
分享 Thread t = null;
bool bExit = false;
private void fun()
{
while (!bExit)
{
}
}
private void button1_Click(object sender, EventArgs e)
{
t = new Thread(new ThreadStart(fun));
t.Start();
t.IsBackground = true;
bExit = false;
}
private void button2_Click(object sender, EventArgs e)
{
//我一般使用这种方法
bExit = true;
System.Threading.Thread.Sleep(1000);
MessageBox.Show(t.IsAlive.ToString());
}
private void button3_Click(object sender, EventArgs e)
{
if (t.IsAlive)
{
t.Abort();
}
System.Threading.Thread.Sleep(1000);
MessageBox.Show(t.IsAlive.ToString());
}