title: One another way to let Timer skip tick if the previous thread is still busy
body: <p>I have the same problem as described in this topic <a href="https://stackoverflow.com/questions/3424907/how-to-let-timer-skip-tick-if-the-previous-thread-is-still-busy">How to let Timer skip tick if the previous thread is still busy</a></p>
  
  <p>I don't know if I should create new topic for my problem, or I can "up" somehow existent thread (please let me know if i'm wrong creating new topic)</p>
  
  <p>I wrote such solution:</p>
  
  <pre><code>Mutex refreshMutex = new Mutex();
  void OnRefreshTimedEvent(object source, ElapsedEventArgs args)
  {
      try
      {
          refreshMutex.WaitOne();
          // do work
      } finally
      {
          refreshMutex.ReleaseMutex();
      }
  }
  </code></pre>
  
  <p>I think it's better because it's thread-safe and doesn't lock entiry object. I would appreciate any comments cause I'm pretty novice in C# :)</p>
  
  <p>Does anyone see any potential problems with what I've shared? I can't ask as an answer on the other discussion.</p>
  
  <p><strong>upd</strong> Well it seems solution above doesn't work (thanks to user24601 for noticing). But I don't like the answer from referenced question because the call to serviceTimer.Stop() is not thread-safe. It could be a problem in the extreme frequent timers theoretically (and probably practically), especially if system is used intensively (100% CPU load etc.). I'm thinking now about such pattern:</p>
  
  <pre><code>[MethodImpl(MethodImplOptions.Synchronized)]
  void serviceTimer_Elapsed(object sender, ElapsedEventArgs e)
  {
      try
      {
        serviceTimer.Stop(); 
        // do some heavy processing... 
      }
      finally
      {
        serviceTimer.Start(); 
      }
  }
  </code></pre>