title: Multithreading design-pattern
body: <p>While keeping in mind that:</p>
  
  <ul>
  <li>I am using a blocking queue that waits for ever until something is added to it </li>
  <li>I might get a FileSystemWatcher event twice</li>
  </ul>
  
  <p>The <strong>updated</strong> code:</p>
  
  <pre><code> {
          FileProcessingManager processingManager = new FileProcessingManager();
          processingManager.RegisterProcessor(new ExcelFileProcessor());
          processingManager.RegisterProcessor(new PdfFileProcessor());
          processingManager.Completed += new ProcessingCompletedHandler(ProcessingCompletedHandler);
          processingManager.Completed += new ProcessingCompletedHandler(LogFileStatus);
          while (true)
          {
              try
              {
                  var jobData = (JobData)fileMonitor.FileQueue.Dequeue();
                  if (jobData == null)
                      break;
  
                  _pool.WaitOne();
                  Application.Log(String.Format("{0}:{1}", DateTime.Now.ToString(CultureInfo.InvariantCulture), "Thread launched"));
                  Task.Factory.StartNew(() =&gt; processingManager.Process(jobData));
              }
              catch (Exception e)
              {
                  Application.Log(String.Format("{0}:{1}", DateTime.Now.ToString(CultureInfo.InvariantCulture), e.Message));
              }
          }
      }
  </code></pre>
  
  <p>What are are you suggestions on making the code multi-threaded while taking into consideration the possibility that two identical string paths may be added into the blocking queue? I have left the possibility that this might happen and in this case.. the file would be processed twice, the thing is that sometimes I get it twice, sometimes not, it is really awkward, if you have suggestions on this, please tell.</p>
  
  <p>The null checking is for exiting the loop, I intentionally add a null from outside the threaded loop to determine it to stop.</p>