I've made a combined start/stop button for starting and stopping a thread.
Looks like this:
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();
}
}
Can i check the threadstate like i do and if stopped init it again? or is it some other way since i cant just start a thread if its stopped?
Yes, you can. You are reusing only the reference to a thread object, setting it to a completely new thread object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With