title: Timer in C# to run once then after X sec run again
body: <p>I have some code where the timer EventHandler has this</p>
  
  <pre><code>void timer_Tick(object sender, EventArgs e)
  {
      try
      {
           timerRescan.Stop();
           ScanForIeInstances()
      }
      catch (Exception ex)
      {
           log.Warn("Exception 3", ex);
      }
      finally
      {
          timerRescan.Start();
      }
  }
  </code></pre>
  
  <p>Naturally there is a race condition with an external entity who may want to Stop the timer down....if the timer is in process and using a thread and someone calls timerRescan.Stop, the timer thread will call Start starting the timer back up again.  I am trying to replace this code.  There are two methods in java I know and I would like to know how to do both in C#</p>
  
  <ol>
  <li>Run a task every 5 seconds where 5 seconds is the distance between tasks firing</li>
  <li>Run a task and AFTER it ends+5seconds run the task again</li>
  </ol>
  
  <p>I would like to use #2 and always fire 5 seconds from the END of the last firing of the event.  How do I do that and which timer do I use in C# for that?  </p>
  
  <p>This then allows me to have a recurring timer, call start once and have no race condition with the stop(I would rather not have to implement synchronization though I know I could do that as a last resort...would rather just keep the code clean like I can in java)</p>
  
  <p>OR IF you know java, what I am simply looking for is the equivalent of
  <code>ScheduledExecutorService.scheduleAtFixedRate</code> - start to start 
  <code>ScheduledExecutorService.scheduleWithFixedDelay</code> - end to start</p>