title: FileSystemWatcher with the console application
body: <p>To send bulk email in my web application I am using filewatcher to send the application.</p>
  
  <p>I have planned to write filewatcher with the console application instead of windows service or scheduler.</p>
  
  <p>I have copied the executable file shortcut in the following path.</p>
  
  <p>%appdata%\Microsoft\Windows\Start Menu\Programs</p>
  
  <p>Ref: <a href="https://superuser.com/questions/948088/how-to-add-exe-to-start-menu-in-windows-10">https://superuser.com/questions/948088/how-to-add-exe-to-start-menu-in-windows-10</a></p>
  
  <p>After run the executable file the file watcher is not watched always.
  After searching some sites, i have found that we need to add the code </p>
  
  <pre><code>new System.Threading.AutoResetEvent(false).WaitOne();
  </code></pre>
  
  <p><strong>Is this the right method to add in the executable file and to watch the folder?</strong></p>
  
  <p><strong>After run the console application (without above code) is the file won't be watched always?</strong></p>
  
  <p>What will be the right method to use the file watcher?</p>
  
  <pre><code>FileSystemWatcher watcher = new FileSystemWatcher();
  string filePath = ConfigurationManager.AppSettings["documentPath"];
  watcher.Path = filePath;
  watcher.EnableRaisingEvents = true;
  watcher.NotifyFilter = NotifyFilters.FileName; 
  watcher.Filter = "*.*";
  watcher.Created += new FileSystemEventHandler(OnChanged);
  </code></pre>