title: Filewatcher queue management
body: <p>I have a filewatcher that is watching a directory for file changes.
  When it happens, each file is queued in a Queue  managed by a FileProcessor class (with Threads).
  I would like to update in a label which in the Form1 the number of files in the Q (everytime that number is updated)
  i tried several things including :</p>
  
  <pre><code>class FileProcessor : IDisposable
  {
     private static Form1 frm;
  </code></pre>
  
  <p>and the call later in the class :</p>
  
  <pre><code>frm.Invoke((MethodInvoker)delegate { frm.button4.Text = Qcounte(); });
  </code></pre>
  
  <p>I have a System.NullReferenceException because i do not know how to declare Form1 in frm :(</p>
  
  <p>Here is the Main form with the function to update the label : SetQ(string s)</p>
  
  <pre><code>public delegate void ddisplayQ(string q);
  public partial class Form1 : Form
  {
      public static ddisplayQ deldisplayQ;
  public Form1()
      {
          InitializeComponent();
          deldisplayQ = new ddisplayQ(this.setQ);
      }
  private void setQ(string s)
      {
          button4.Text = s;
      }
  </code></pre>
  
  <p>on the FileProcessor class, here is how i'm calling the update of the label :</p>
  
  <pre><code>Form1.deldisplayQ.Invoke(Qcounte());
  
  public string Qcounte()
      {
          return Convert.ToString(fileNamesQueue.Count);
      }
  
              Form1.deldisplayQ.Invoke(Qcounte());
  </code></pre>
  
  <p>Here is the whole class :</p>
  
  <pre><code> class FileProcessor : IDisposable
  {
      private EventWaitHandle eventWaitHandle = new AutoResetEvent(false);
      private Thread worker;
      private readonly object locker = new object();
      private Queue&lt;string&gt; fileNamesQueue = new Queue&lt;string&gt;();
      public static Form1 frm ;
       public FileProcessor()
      {
          worker = new Thread(Work);
          worker.Start();
      }
  
      public void EnqueueFileName(string FileName)
      {
          lock (locker) fileNamesQueue.Enqueue(FileName);
          eventWaitHandle.Set();
      }
      private void Work()
      {
          while (true)
          {
              string fileName = null;
              lock (locker)
                  if (fileNamesQueue.Count &gt; 0)
                  {
                      if (fileName == null) return;
                  }
              if (fileName != null)
              {
                  ProcessFile(fileName);
              }
              else
              {
                  eventWaitHandle.WaitOne();
              }
          }
      }
      private void ProcessFile(string FileName)
      {
          Globals.getTags(FileName);
          Globals.ecritDb(FileName);
      }
      public string Qcounte()
      {
          return Convert.ToString(fileNamesQueue.Count);
      }
      #region IDisposable Members
  
      public void Dispose()
      {
          EnqueueFileName(null);
          worker.Join();
          eventWaitHandle.Close();
      }
  
      #endregion
  }
  </code></pre>
  
  <p>My question is :
  Where to trigger the enqueue and the dequeue in the FileProcessor class so that i can see the increase and the decrease of the file processing in my main form ?
  thanks in advance</p>