求助,C#如何安全的关闭线程,之后在重新打开这个线程

如题所述

private void display()
{
while (ff == true)
{

}
}

void button1_Click(object sender, EventArgs e)
{
if (button1.Text == "开始监控")
{
ff=true;
Thread a = new Thread(new ThreadStart(display));
a.Start();
button1.Text = "停止监控";
}
else
{
a.Abort();
serialPort1.Close();
button1.Text = "开始监控";
ff = false;
}
}
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答