线程被终止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()
{
。。。
}
线程正在运行或被终止;它无法重新启动。
时间: 2024-10-12 23:18:53