title: c# windows service not firing elapsed event handler
body: <p>I have a windows service running 2 timers, one on a 15 minute interval one on 24 hours.
  I added event logging to check that the elapsed event handler was firing on the 15 minute one but it doesn't seem to.  Can anyone see anything wrong with this code?  </p>
  
  <pre><code>public partial class GTstaging : ServiceBase
      {
          System.Timers.Timer regularTimer = new System.Timers.Timer();
          System.Timers.Timer longTimer = new System.Timers.Timer();
          DateTime _scheduleTime;
  
          public staging()
          {
              InitializeComponent();
              _scheduleTime = DateTime.Today.AddDays(1).AddHours(Convert.ToDouble(ConfigurationManager.AppSettings["ScheduleTime_" + DateTime.Now.DayOfWeek.ToString()]));
          }
  
          protected override void OnStart(string[] args)
          {
              //** original - ConsoleApplication1.Program.DoProcessing();
  
              using (EventLog eventLog = new EventLog("Application"))
              {
                  eventLog.Source = "Application";
                  eventLog.WriteEntry("START, regular timer:" + ConfigurationManager.AppSettings["RegularTimer"], EventLogEntryType.Information, 101, 1);
              }
  
              this.regularTimer.Enabled = true;
              this.regularTimer.Interval = Convert.ToDouble(ConfigurationManager.AppSettings["RegularTimer"]);
              this.regularTimer.AutoReset = true;
              this.regularTimer.Elapsed += new System.Timers.ElapsedEventHandler(this.DoRegular);
  
              this.longTimer.Enabled = true;
              this.longTimer.Interval = _scheduleTime.Subtract(DateTime.Now).TotalSeconds * 1000;
              this.longTimer.Elapsed += new System.Timers.ElapsedEventHandler(this.DoLongRunning);
  
          }
  
          private void DoRegular(object sender, System.Timers.ElapsedEventArgs e)
          {
  //do stuff then log
                  using (EventLog eventLog = new EventLog("Application"))
                  {
                      eventLog.Source = "Application";
                      eventLog.WriteEntry("Regular Process End", EventLogEntryType.Information, 101, 1);
                  }
          }
  
          private void DoLongRunning(object sender, System.Timers.ElapsedEventArgs e)
          {
              //do stuff
          }
  
          protected override void OnStop()
          {
              this.regularTimer.Stop();
              this.longTimer.Stop();
              this.regularTimer = null;
              this.longTimer = null;
          }
  
      }
  }
  </code></pre>