title: Only raise an event if the previous one was completed
body: <p>I'm using a <code>System.Timers.Timer</code> in my application. Every second I run a function which does some job. The thing is, this function can block for some little time (it reads then processes a large file from disk). I want to start that function only if its previous "execution instance" has completed. I thought I could achieve this with a <code>Mutex</code>:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Timers;
  using System.Threading;
  
  namespace ConsoleApplication1
  {
      class Program
      {
          static Mutex TimerMut = new Mutex(false);
          public static void Main()
          {
  
              Thread TT = new Thread(new ThreadStart(delegate()
              {
                  System.Timers.Timer oTimer = new System.Timers.Timer();
                  oTimer.Elapsed += new ElapsedEventHandler(Handler);
  
                  oTimer.Interval = 1000;
                  oTimer.Enabled = true;
              }));
  
              TT.Start();
  
              Console.Read();
          }
  
          private static void Handler(object oSource,
              ElapsedEventArgs oElapsedEventArgs)
          {
              TimerMut.WaitOne();
              Console.WriteLine("foo");
              Thread.Sleep(500);         //simulate some work
              Console.WriteLine("bar");
              TimerMut.ReleaseMutex();
          }
      }
  }
  </code></pre>
  
  <p>That doesn't work, "foos" still appear every second. How can I achieve this?</p>
  
  <p>EDIT: You're right, it makes no sense to start a new thread to handle this. I thought only <code>System.Threading.Timer</code> is launched in a separate thread.</p>