title: Execute code in console application every minute
body: <p>I have a simple application in C# which takes PDF from one location and moves it to another location.</p>
  
  <pre><code>namespace MoveFiles
  {
  class Program
  {
      public static string destinationPath = @"S:\Re\C";
      static void Main(string[] args)
      {
  
          //location of PDF files
  
          string path = @"S:\Can\Save";
  
          //get ONLY PDFs
  
          string[] filePath = Directory.GetFiles(path, "*.pdf");
  
  
          foreach (string file in filePath)
          {
              Console.WriteLine(file);
              string dest = destinationPath + "\\" + Path.GetFileName(file);
              File.Move(file, dest);
          }
          Console.ReadKey();
  
  
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>If I run this app it does the work, however, I need this code to be executed every minute. I could of used <code>task scheduler</code> to run the app every minute, but unfortunately the minimum runtime is 5 min.</p>
  
  <p>I have tried to use <code>while(true)</code> but it doesn't work. If I add more PDF files to the folder while the app is running it will not move it to different folder.</p>
  
  <p>I found a suggestion online to use <code>Timer</code> but I'm having issues:</p>
  
  <pre><code>static void Main(string[] args)   
  {
      Timer t = new Timer(60000); // 1 sec = 1000, 60 sec = 60000
      t.AutoReset = true;
      t.Elapsed += new System.Timers.ElapsedEventHandler(t_Elapsed);
      t.Start();
    }
    private static void t_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
       // do stuff every minute
     }
  </code></pre>
  
  <p>But I get compiler errors:</p>
  
  <blockquote>
    <p>Error 2   Argument 1: cannot convert from 'int' to 'System.Threading.TimerCallback'   C:\Win\MoveFiles\MoveFiles\MoveFiles\Program.cs 22  33  MoveFiles</p>
  </blockquote>
  
  <p>Any suggestions on how I can resolve this issue?</p>