5
我製作了一個用於啓動和停止線程的組合啓動/停止按鈕。啓動停止的線程?
是這樣的:
private void btStartStop_Click(object sender, EventArgs e)
{
if (btStartStop.Text.Equals("Start"))
{
btStartStop.Text = "Stop";
stopThread = false;
ThreadState ts = thread.ThreadState;
if (thread.ThreadState == ThreadState.Stopped)
thread = new Thread(DoWork);
thread.Start();
}
else
{
btStartStop.Text = "Start";
stopThread = true;
thread.Join();
}
}
我可查的ThreadState像我這樣做,如果再次停止初始化呢?還是有其他的方式,因爲我不能只是開始一個線程,如果它停止?