title: C# - Windows Service, thread, timer - not run
body: <p>This is my code for Windows Service...but unfortunately, the method myTimer_Elapsed() is invoked only when at least 60 sec. after starting the service. Why not start immediately after switching service?</p>
  
  <pre><code>public partial class MyService : ServiceBase
  {
      private System.Threading.Thread myWorkingThread;
      private System.Timers.Timer myTimer = new System.Timers.Timer();
  
      protected override void OnStart(string[] args)
      {
          myWorkingThread = new System.Threading.Thread(PrepareTask);
          myWorkingThread.Start();
      }
  
      private void PrepareTask()
      {
          myTimer.Elapsed += new System.Timers.ElapsedEventHandler(myTimer_Elapsed);
          myTimer.Interval = 60000;
          myTimer.Start();
          System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
      }
  
      void myTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
      {
          ..my code to prepare binary db files
      BinaryDB rdr = new BinaryDB();
      rdr.ReadFile(...)
      }
  
  }
  </code></pre>