title: How to copy file from folder to another folder with Windows Service C#
body: <p>How to copy file from folder to another folder with Windows Service C#</p>
  
  <p>I try this code to copy file every 30 sec. But time loop is fine, So copy can't be done.
  So I use Visual Studio 2012. I will install Windows Service with command line.
  How do I fix this code.</p>
  
  <pre><code>using System.ServiceProcess;
  using System.Text;
  using System.Threading;
  using System.Timers;
  using System.IO;
  using TestWindowService;
  
  namespace TestCopy
  {
      public partial class Copy : ServiceBase
      {
          private FileSystemWatcher watcher;
          private System.Timers.Timer timer1 = null;
          public Copy()
          {
             InitializeComponent(); 
          }
  
          protected override void OnStart(string[] args)
          {
              //File.Copy(@"C:\input\*.*", @"D:\output\*.*");
              Library.WriteErrorLog("Test window service started");
              timer1 = new System.Timers.Timer();
              this.timer1.Interval = 30000; //every 30 secs
              this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Tick);
              timer1.Enabled = true;
              watcher = new FileSystemWatcher();
              watcher.Path = "C:\\INPUT\\";
              watcher.Filter = "*.*";
              watcher.EnableRaisingEvents = true;
          }
  
          private void OnCreated(object sender, FileSystemEventArgs e)
          {
              String output_dir = "D:\\OUTPUT\\";
              String output_file = Path.Combine(output_dir, e.Name);
              File.Copy(e.FullPath, output_file);
              // File.Copy() works here
              Library.WriteErrorLog("File copy success");
          }
  
          private void timer1_Tick(object sender, ElapsedEventArgs e)
          {
              watcher.Created += new FileSystemEventHandler(OnCreated);                 
          }
  
          protected override void OnStop()
          {
              timer1.Enabled = false;
              Library.WriteErrorLog("Test window service stopped"); 
          }
      }
  }
  </code></pre>