Suppose I have a routine like this:
private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(Some_Work));
t.Start();
}
I need to put a condition so that, “If there is not already a thread running apart from the Main thread, start a new thread”.
But how to test for whether a thread is running other than the Main thread?
The easiest solution is of course to either store a reference to the existing thread, or just set a flag that you have a thread running.
You should also maintain that field (reference or flag) so that if the thread exits, it should unset that field so that the next “start request” starts a new one.
Easiest solution: