title: Is there a simple way to avoid or stop FileSystemWatcher raise event twice in C#?
body: <p>I want to know what how to avoid or stop <code>FileSystemWatcher</code> raise event twice in C#? I have a solution that will detect everytime if there is newly created xml file from a folder. I test my application using creating xml file using notepad but from the listbox it displays twice.</p>
  
  <p>How can I fix this issue?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>private void fileSystemWatcher1_Created(object sender, System.IO.FileSystemEventArgs e)
      {
          try
          {
              fileSystemWatcher1.EnableRaisingEvents = false;
              listBox1.Items.Add(e.FullPath);
          }
  
          finally
          {
              fileSystemWatcher1.EnableRaisingEvents = true;
          }
      }
  
      private void button1_Click(object sender, EventArgs e)
      {
          DialogResult dialogSelectFolder = folderBrowserDialog1.ShowDialog();
          if (dialogSelectFolder.ToString() == "OK")
          {
              textBox1.Text = folderBrowserDialog1.SelectedPath;
              button2.Enabled = true;
          }
      }
  
      private void button2_Click(object sender, EventArgs e)
      {
          button1.Enabled = false;
          button2.Enabled = false;
          button3.Enabled = true;
          fileSystemWatcher1.EnableRaisingEvents = true;
          fileSystemWatcher1.Path = textBox1.Text;
          fileSystemWatcher1.Filter = "*.xml";
      }
  
      private void button3_Click(object sender, EventArgs e)
      {
          button1.Enabled = true;
          button3.Enabled = false;
          textBox1.Text = "";
          fileSystemWatcher1.EnableRaisingEvents = false;
      }
  }
  </code></pre>