title: Restarting a windows service after a fixed time interval
body: <p>I am developing a windows service that sends automated e-mail in every 15 minutes. I am using a timer to use the service again after a fixed time interval (15 minutes) but its not working.</p>
  
  <pre><code>namespace Mailer
  {
    public partial class Mailer : ServiceBase
    {
      System.Timers.Timer createOrderTimer;
      public Mailer()
      {
        InitializeComponent();
      }
  
      protected override void OnStart(string[] args)
      {
        sendmail();  //function to send email.
  
        createOrderTimer = new System.Timers.Timer();                      
        createOrderTimer.Elapsed += new  System.Timers.ElapsedEventHandler(createOrderTimer_Elapsed);
        createOrderTimer.Interval = 15000;
        createOrderTimer.Enabled = true;
        createOrderTimer.AutoReset = true;                      
        createOrderTimer.Start();
      }
  
      protected void createOrderTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs args)
      {
        createOrderTimer.Stop();
        ServiceController controller = new ServiceController("Mailer");
        controller.Start();
      }
  
      protected void sendmail
      {
        //code to send email.
      }
  
      protected override void OnStop() {  }
    }
  }
  </code></pre>
  
  <p>Initially the email is sent but I want the email sending to be performed in every 15 minutes.</p>