title: Waking thread every n seconds
body: <p>I am writing a WPF application using C# and I need some help with threading. I have three classes, each need to be running a task every n seconds in their own thread. This is how I did it with Qt4:</p>
  
  <pre><code>class myThread : public QThread
  {
      void run (void)
      {
          while (true)
          {
              mMutex.lock();
              mWaitCondition.wait (&amp;mMutex);
  
              // Some task
  
              mMutex.unlock();
          }
      }
  
      void wait (int timeout)
      {
          // For shutdown purposes
          if (mMutex.tryLock (timeout))
              mMutex.unlock();
      }
  
      void wake (void)
      {
          mWaitCondition.wakeAll();
      }
  }
  
  // Some other class has a timer which ticks
  // every n seconds calling the wake function
  // of the myThread class.
  </code></pre>
  
  <p>What I get from this is a controlled update interval. So if I am updating 60 times a second, if the code is slow and can only run 30 times a second, it has no problem doing that, but it will never run more than 60 times a second. It will also not run the same code more than one time at the same time. Whats the easiest way of implementing this in C#?</p>