title: MSMQ and polling to receive messages?
body: <p>I've got a windows <em>service</em> that does some image conversion. It works by firing off when any file (in a particular folder) is renamed (ie. rename file watcher). Works great until I have a massive amount of images dumped (and renamed) in that folder. CPU redlines, etc..</p>
  <p>So, I was going to change my code to use <strong>MSMQ</strong> to queue all the files that need to be converted. Fine. Everytime the file is renamed and the file watcher fires, i then add a new message to the queue. Kewl.</p>
  <p>Problem is this -&gt; <strong>how do i grab one message at a time from the queue?</strong></p>
  <p><strike>Do I need to make a timer object that polls the queue every xxx seconds? Or is there a way to constantly keep peeking the first item in the queue. Once a message exists, extract it, process it, then continue (which .. means, keep peeking until the world blows up).</strike></p>
  <p>I've wondered if i just need to put a while loop around the Receive method. Pseduo code is below (in Edit #2)...</p>
  <p>Anyone have any experience with this and have some suggestions?</p>
  <p>Thanks kindly!</p>
  <h3>EDIT:</h3>
  <p>If WCF is the way to go, can someone provide some sample code, etc instead?</p>
  <h3>EDIT 2:</h3>
  <p>Here's some pseudo code i was thinking off....</p>
  <pre><code>// Windows service start method.
  protected override void OnStart(string[] args)
  {
     // some initialisation stuf...
  
     // Start polling the queue.
     StartPollingMSMQ();
  
     // ....
  }
  
  private static void StartPollingMSMQ()
  {
      // NOTE: This code should check if the queue exists, instead of just assuming it does.
      //       Left out for berevity.
      MessageQueue messageQueue = new MessageQueue(&quot;.\\Foo&quot;);
  
      while (true)
      {
          // This blocks/hangs here until a message is received.
          Message message = messageQueue.Receive(new TimeSpan(0, 0, 1));
  
          // Woot! we have something.. now process it...
          DoStuffWithMessage(message);
  
          // Now repeat for eva and eva and boomski...
      }
  }
  </code></pre>