title: FileWatcher creation event not fired
body: <p>I wrote a filewatcher service for monitoring a directory recursively, and if there is .txt file contents change or new created .txt files in the directory, it will copy the file to an central folder. But I meet some problem in my program.</p>
  
  <p>Whenever there is a .txt file contents change, my program works well. However, when there is a new .txt file created in the directory, the created event never fired. Below is my code, could you please help me with this problem? Thanks in advance!</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Diagnostics;
  using System.Linq;
  using System.ServiceProcess;
  using System.Text;
  using System.Threading.Tasks;
  using System.IO;
  
  namespace FileWatcher
  {
      public partial class FileWatcher : ServiceBase
      {
          private string des = @"c:\b";
          private FileSystemWatcher watcher;
          public FileWatcher()
          {
              InitializeComponent();
              watcher = new FileSystemWatcher();
          }
  
          protected override void OnStart(string[] args)
          {
  
  
              watcher.Path = @"C:\a";
              /* Watch for changes in LastAccess and LastWrite times, and
                 the renaming of files or directories. */
              watcher.NotifyFilter = NotifyFilters.Size | NotifyFilters.LastWrite;
  
              // Only watch text files.
              watcher.Filter = "*.txt";
  
              // Add event handlers.
              watcher.Changed += new FileSystemEventHandler(OnChanged);
              watcher.Created += new FileSystemEventHandler(OnCreated);
  
  
              // Begin watching.
              watcher.IncludeSubdirectories = true;
              watcher.EnableRaisingEvents = true;
          }
          private void OnChanged(object sender, FileSystemEventArgs e) {
  
              string fileName = Path.GetFileName(e.Name);
              string destFile = System.IO.Path.Combine(des, fileName);
              using (System.IO.StreamWriter f = new System.IO.StreamWriter(@"C:\log.txt", true))
              {
                  f.WriteLine(fileName);
              }
  
  
              using (System.IO.StreamWriter f = new System.IO.StreamWriter(@"C:\log.txt", true))
              {
                  f.WriteLine(destFile);
              }
  
              System.IO.File.Copy(e.FullPath, destFile, true);
  
          }
  
          private void OnCreated(object sender, FileSystemEventArgs e) {
              using (System.IO.StreamWriter f = new System.IO.StreamWriter(@"C:\log.txt", true))
              {
                  f.WriteLine("create new");
              }
  
              FileAttributes attr = File.GetAttributes(e.FullPath);
              //detect whether its a directory or file
              if ((attr &amp; FileAttributes.Directory) == FileAttributes.Directory) {
                  foreach (string file in Directory.GetFiles(e.FullPath))
                  {
                      var eventArgs = new FileSystemEventArgs(
                          WatcherChangeTypes.Created,
                          Path.GetDirectoryName(file),
                          Path.GetFileName(file));
                      OnCreated(sender, eventArgs);
                  }
  
  
              }
              else {
                  string fileName = e.Name;
                  string destFile = System.IO.Path.Combine(des, fileName);
                  System.IO.File.Copy(e.FullPath, destFile, true);
              }
  
  
          }
  
  
          protected override void OnStop()
          {
  
          }
      }
  }
  </code></pre>