title: which timer to use to introduce 1-5 ms delay between iterations?
body: <p>In my previous question <a href="https://stackoverflow.com/questions/10270438/how-to-suspend-a-thread-for-1-ms">how to suspend a thread for 1 ms?</a> it was answered that to introduce delay of 1 ms I should use Timer.</p>
  
  <p>I need to "do work" then wait 2 ms in average (1-5 ms is ok, it's ok to have <strong>rarely</strong> extreme delays up to several hundreads ms), then do work again. It's important not to try to start new iteration when previous iteration still not finished, so I don't need to do something every 1-5 ms, I need 1-5 ms delay between iterations.</p>
  
  <p>I've tried to do that using <code>System.Timers.Timer</code> but it doesn't work:</p>
  
  <pre><code>using System;
  using System.Diagnostics;
  using System.Threading;
  using System.Timers;
  using Timer = System.Timers.Timer;
  
  namespace TestTimer
  {
      class Program
      {
          static Timer refresh_timer;
          private static int called;
          private const int ITERATIONS = 100;
          private static Stopwatch sw;
  
          static void Main(string[] args)
          {
              refresh_timer = new Timer(1);
              refresh_timer.AutoReset = false;
              refresh_timer.Elapsed += OnRefreshTimedEvent;
              sw = Stopwatch.StartNew();
              refresh_timer.Start();
              Thread.Sleep(10000);
          }
  
          static void OnRefreshTimedEvent(object source, ElapsedEventArgs args)
          {
              DoGateIteration();
          }
  
          private static void DoGateIteration()
          {
              //try
              //{
                  // work here
                  called++;
              //}
              //finally
              //{
                  if (called == ITERATIONS)
                  {
                      Console.WriteLine("Average iterations per second: " + ITERATIONS * 1000 / sw.ElapsedMilliseconds);
                      Console.WriteLine("Average iterations milliseconds: " + sw.ElapsedMilliseconds / ITERATIONS);
                  }
                  refresh_timer.Start();
              //}
          }
      }
  }
  </code></pre>
  
  <p>It reports:</p>
  
  <pre><code>Average iterations per second: 64
  Average iterations milliseconds: 15
  </code></pre>
  
  <p>So it seems <code>System.Timers.Timer</code> is not as precise as I need.
  Probably I should try <code>System.Threading.Timer</code>, but this timer doesn't have <code>AutoReset</code> property that I need.</p>
  
  <p>What would you suggest?</p>