线程正在运行或被终止;它无法重新启动。

时间:2023-01-20 17:43:07

线程被终止abort了无法再次启动,可以先挂起suspend,再resume()

 

bool bl = false;

Thread thrd;

public Form1()
{
InitializeComponent();
thrd = new Thread(tAR);
}

private void btn_Click(object sender, EventArgs e)
{

if (bl == false)
{
if (thrd.ThreadState == ThreadState.Suspended)
{

thrd.Resume();

}
else
{
thrd.Start();
}
bl = true;
}
else
{
if (thrd.IsAlive == true)
{
this.thrd.Suspend();
}
bl = false;
}
}

 private void tAR()

{

。。。

}