title: Safely start new worker thread on interval C#
body: <p>I have a worker thread to do some background work. I want it to run periodically. I don't want more then one instance of this thread executing at the same time. Because i don't want the number of threads to spiral out of control. </p>
  
  <p>I start my threads on a timer like so:</p>
  
  <pre><code>intervalTimer = new Timer(millisecondInterval);
          intervalTimer.AutoReset = true;
          intervalTimer.Elapsed += StartThread;
  </code></pre>
  
  <p>...</p>
  
  <pre><code>private void StartThread(object sender, ElapsedEventArgs e)
      {
          Thread workerThread = new Thread(new ThreadStart(RunTest));
          workerThread.Start();
      }  
  </code></pre>
  
  <p>This does not feel safe to me as i may be starting new threads before the first one has finished executing. What is the safe way to implement this.</p>
  
  <p>Thanks</p>