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

线程被终止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()

{

。。。

}

 

转载于:https://www.cnblogs.com/3Sblogs/p/3913093.html

你可能感兴趣的:(c#)