title: How to let Timer skip tick if the previous thread is still busy
body: <p>I created a windows service, that is supposed to check a certain table in the db for new rows every 60 seconds. For every new row that was added, I need to do some heavy processing on the server that could sometimes take more than 60 seconds.</p>
  
  <p>I created a Timer object in my service, that ticks every 60 seconds and invokes the wanted method.<br>
  Since I don't want this timer to tick while processing the new lines found, I wrapped the method in a <code>lock { }</code> block, so this won't be accessible by another thread.</p>
  
  <p>It looks something like this :</p>
  
  <pre><code>Timer serviceTimer = new Timer();
  serviceTimer.Interval = 60;
  serviceTimer.Elapsed += new ElapsedEventHandler(serviceTimer_Elapsed);
  serviceTimer.Start();
  
  void serviceTimer_Elapsed(object sender, ElapsedEventArgs e)
  {
      lock (this)
      {
          // do some heavy processing...
      }
  }
  </code></pre>
  
  <p>Now, I'm wondering -<br>
  If my timer ticks, and finds a lot of new rows on the db, and now the processing will take more than 60 seconds, the next tick won't do any processing till the previous one finished. This is the effect I want.</p>
  
  <p>But now, will the serviceTimer_Elapsed method go off immediatly once the first processing was finished, or will it wait for the timer to tick again.</p>
  
  <p>What I want to happen is - if the processing requires more than 60 seconds, than the timer will notice the thread is locked, and wait another 60 seconds to check again so I will never get stuck in a situation where there are a queue of threads waiting for the previous one to finish.</p>
  
  <p>How can i accomplish this result ?<br>
  What is the best practice for doing this ?</p>
  
  <p>Thanks!</p>