title: How to run multiple Scheduler within single Windows Service?
body: <p>I'm new to windows service. I had created a windows service which has multiple Scheduler. Each Scheduler should run in different time interval. Please help me to know whether it will work within single WS.</p>
  
  <p>my code is here.</p>
  
  <pre><code> private Timer Schedular1;
   private Timer Schedular2;
   public void ScheduleService()
      {
          try
          {
              Schedular1 = new Timer(new TimerCallback(SchedularCallback1));
              Schedular2 = new Timer(new TimerCallback(SchedularCallback2));
              this.WriteToFile("Simple Service Mode: " + mode + " {0}");
  
              //Set the Default Time.
              DateTime scheduledTime = DateTime.MinValue;
  
  
              //Get the Scheduled Time from AppSettings.
              scheduledTime = DateTime.Parse(System.Configuration.ConfigurationManager.AppSettings["ScheduledTime"]);
              if (DateTime.Now &gt; scheduledTime)
              {
                  //If Scheduled Time is passed set Schedule for the next day.
                  scheduledTime = scheduledTime.AddDays(1);
              }
  
  
  
              TimeSpan timeSpan = scheduledTime.Subtract(DateTime.Now);
              string schedule = string.Format("{0} day(s) {1} hour(s) {2} minute(s) {3} seconds(s)", timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);
  
              this.WriteToFile("Simple Service scheduled to run after: " + schedule + " {0}");
  
              //Get the difference in Minutes between the Scheduled and Current Time.
              int dueTime1 = Convert.ToInt32(timeSpan.TotalMilliseconds);
              int dueTime2 = Convert.ToInt32(timeSpan.TotalMilliseconds) + 100000;
  
              //Change the Timer's Due Time.
              Schedular1.Change(dueTime1, Timeout.Infinite);
              Schedular2.Change(dueTime2, Timeout.Infinite);
          }
          catch(Exception ex)
          {
              WriteToFile("Simple Service Error on: {0} " + ex.Message + ex.StackTrace);
  
              //Stop the Windows Service.
              using (System.ServiceProcess.ServiceController serviceController = new System.ServiceProcess.ServiceController("SimpleService"))
              {
                  serviceController.Stop();
              }
          }
      }
  
       private void SchedularCallback1(object e)
      {
          this.WriteToFile("I'm in SchedularCallback1");
          this.ScheduleService();
      }
  
       private void SchedularCallback2(object e)
      {
          this.WriteToFile("I'm in SchedularCallback2");
          this.ScheduleService();
      }
  </code></pre>
  
  <p>I want to know that whether this Scheduler1,Scheduler2 will work correctly without any problems?  </p>