title: FileSystemwatcher for a list of files
body: <p>I have been following the guidance here <a href="https://stackoverflow.com/questions/1764809/filesystemwatcher-changed-event-is-raised-twice">FileSystemWatcher Changed event is raised twice</a>.</p>
  
  <p>However I have a list of files that I'm watching so if I delete 20 files together the event is called 20 times. This is expected and works fine.</p>
  
  <p>How can I only have an event fired once for 20 "simultaneous" file changes (i.e How can I ignore all other file changes until the code in the first instance of <code>Onchanged</code> below has completed. Right now <code>Onchanged</code> is called 20 times.) ?</p>
  
  <pre><code>private void Main_Load(object sender, EventArgs e)
  {
      public static List&lt;FileSystemWatcher&gt; watchers = new List&lt;FileSystemWatcher&gt;();
      UpdateWatcher();
  }
  
  
  public void OnChanged(object sender, FileSystemEventArgs e)
  {
      try
      {
        Logging.Write_To_Log_File("Item change detected " + e.ChangeType + " " + e.FullPath + " " + e.Name, MethodBase.GetCurrentMethod().Name, "", "", "", "", "", "", 2);
        watchers.Clear();
  
        foreach (FileSystemWatcher element in MyGlobals.watchers)
        {
          element.EnableRaisingEvents = false;
        }
  
        //Do some processing on my list of files here....
        return;
  
      }    
      catch (Exception ex)
      {
         // If exception happens, it will be returned here
      }                
      finally
      {
           foreach (FileSystemWatcher element in MyGlobals.watchers)
           {
              element.EnableRaisingEvents = true;
           }
      }
  }
  
  
  
  
  
  public void UpdateWatcher() // Check Items
          {
  
          try
          {
          watchers.Clear();
  
          for (int i = 0; i &lt; MyGlobals.ListOfItemsToControl.Count; i++) // Loop through List with for
          {
          FileSystemWatcher w = new FileSystemWatcher();
           w.Path = Path.GetDirectoryName(MyGlobals.ListOfItemsToControl[i].sItemName); // File path    
          w.Filter = Path.GetFileName(MyGlobals.ListOfItemsToControl[i].sItemName); // File name
          w.Changed += new FileSystemEventHandler(OnChanged);
          w.Deleted += new FileSystemEventHandler(OnChanged);
          w.Created += new FileSystemEventHandler(OnChanged);
          w.EnableRaisingEvents = true;
          watchers.Add(w);
          }
          }
          catch (Exception ex)
          {
          // If exception happens, it will be returned here
  
          }
          }
  </code></pre>