title: How would you change my Heartbeat process written in C#?
body: <p>I'm looking at implementing a "Heartbeat" process to do a lot of repeated cleanup tasks throughout the day.</p>
  
  <p>This seemed like a good chance to use the Command pattern, so I have an interface that looks like:</p>
  
  <pre><code>   public interface ICommand
     {
         void Execute();
         bool IsReady();
     }
  </code></pre>
  
  <p>I've then created several tasks that I want to be run.  Here is a basic example:</p>
  
  <pre><code>public class ProcessFilesCommand : ICommand
  {
      private int secondsDelay;
      private DateTime? lastRunTime;
  
      public ProcessFilesCommand(int secondsDelay)
      {
          this.secondsDelay = secondsDelay;
      }
  
      public void Execute()
      {
          Console.WriteLine("Processing Pending Files...");
          Thread.Sleep(5000); // Simulate long running task
          lastRunTime = DateTime.Now;
      }
  
      public bool IsReady()
      {
          if (lastRunTime == null) return true;
  
          TimeSpan timeSinceLastRun = DateTime.Now.Subtract(lastRunTime.Value);
          return (timeSinceLastRun.TotalSeconds &gt; secondsDelay);
      }
  
  }
  </code></pre>
  
  <p>Finally, my console application runs in this loop looking for waiting tasks to add to the ThreadPool:</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
  
          bool running = true;
  
          Queue&lt;ICommand&gt; taskList = new Queue&lt;ICommand&gt;();
          taskList.Enqueue(new ProcessFilesCommand(60)); // 1 minute interval
          taskList.Enqueue(new DeleteOrphanedFilesCommand(300)); // 5 minute interval
  
          while (running)
          {
              ICommand currentTask = taskList.Dequeue();
              if (currentTask.IsReady())
              {
                  ThreadPool.QueueUserWorkItem(t =&gt; currentTask.Execute());
              }
              taskList.Enqueue(currentTask);
              Thread.Sleep(100);
          }
  
      }
  }
  </code></pre>
  
  <p>I don't have much experience with multi-threading beyond some work I did in Operating Systems class.  However, as far as I can tell none of my threads are accessing any shared state so they should be fine.</p>
  
  <p>Does this seem like an "OK" design for what I want to do?  Is there anything you would change?</p>