title: How would you limit the number of operations per second?
body: <p>How would you limit the number of operations per second?</p>
  
  <p>Lets say we have to copy files from one location to another and we don't want more than 5 files to be processed per second.</p>
  
  <p>Please see what I am doing</p>
  
  <pre><code>private static string currentStamp;
  private static int processedInCurrentStamp = 0;
  
  private static void Main(string[] args)
  {
      currentStamp = DateTime.Now.ToString("{0:d/M/yyyy HH:mm:ss}");
      Run();
  }
  
  private static void Run()
  {
      for (int i = 0; i &lt; Int32.MaxValue; i++)
      {
          string s = DateTime.Now.ToString("{0:d/M/yyyy HH:mm:ss}");
          if (currentStamp.Equals(s))
          {
              if (processedInCurrentStamp &lt; 5)
              {
                  ProcessItem();
                  processedInCurrentStamp++;
              }
          }
          else
          {
              Console.WriteLine("{0} ::: {1}", currentStamp, processedInCurrentStamp);
              currentStamp = s;
              processedInCurrentStamp = 0;
          }
      }
  }
  </code></pre>
  
  <p>But I need a more elegant and bullet proof way.</p>