求助,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;
}
}
{
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;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询