title: Windows service and timer in C#
body: <p>I need help to write a windows service with a timer that can call 3 different function(events) in 3 different times every day.
  Some code example please. Thank you.</p>
  
  <pre><code> private System.Timers.Timer timer;
      protected override void OnStart(string[] args)
      {
  
          this.timer1 = new System.Timers.Timer(60000); 
          this.timer1.AutoReset = true;
          this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Elapsed);
          this.timer1.Start();
  
      }
  
  private DateTime _lastRun1 = DateTime.Now.AddDays(-1);
  private DateTime _lastRun2 = DateTime.Now.AddDays(-1);
  private DateTime _lastRun3 = DateTime.Now.AddDays(-1);
  
      private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
      {
  
          if (_lastRun.Date &lt; DateTime.Now.Date &amp;&amp; DateTime.Now.Hour == 13)
          {
              //call functionX
  
           DateTime _lastRun1 = DateTime.Now.AddDays(1);
          }
          if (_lastRun.Date &lt; DateTime.Now.Date &amp;&amp; DateTime.Now.Hour == 14)
          {
             //call functionY
           DateTime _lastRun2 = DateTime.Now.AddDays(1);
          }
    if (_lastRun.Date &lt; DateTime.Now.Date &amp;&amp; DateTime.Now.Hour == 16)
          {
             //call functionXY
           DateTime _lastRun3 = DateTime.Now.AddDays(1);
          }
  }
  </code></pre>