title: Windows service start, stop, debug problems
body: <p>I have a service that I don't know the runtime of, I guess around 7 seconds. For some reason the service stops working after the first run and I can't debug it. It keeps saying "starting" on the services manager and I can't find it on the attach process window. </p>
  
  <p>When I try to stop it, the stop button appears for only a second. Even if I press it I get an error saying "windows could not stop the service 'Splive on local computer. the service did not return an error. this could be an internal windows error or internal service error."</p>
  
  <p>What would be the best way to handle this issue?</p>
  
  <pre><code>static void Main(string[] args)
      {
          ServiceBase.Run(new Program());
          ServiceController service = new ServiceController();
          service.ServiceName = "SpLive";
          service.Start();
          //Sp objSportingbet = new Sp();
          //objSportingbet.getListingsFromSp();
      }
      public Program()
      {
          this.ServiceName = "SpLive";
      }
      protected override void OnStart(string[] args)
      {
          base.OnStart(args);
          objSportingbet.getListingsFromSp();
          timer1.Elapsed += new ElapsedEventHandler(timer1_Elapsed);
          timer1.Interval = 7000;
          timer1.Enabled = true;
          timer1.Start();
      }
      protected override void OnStop()
      {
          base.OnStop();
          timer1.Elapsed += new ElapsedEventHandler(timer1_Elapsed);
          timer1.Interval = 7000;
          timer1.Enabled = false;
          timer1.Start();
      }
      private void timer1_Elapsed(object sender, EventArgs e)
      {
          ServiceController service = new ServiceController();
          service.ServiceName = "Sp";
          if (service.Status == ServiceControllerStatus.Stopped)
          {
              service.Start();
          }
          if (service.Status == ServiceControllerStatus.Running)
          {
              service.Stop();
          }
          timer1.Stop();
      }
  
      private void InitializeComponent()
      {
          // 
          // Program
          // 
          this.CanPauseAndContinue = true;
          this.CanShutdown = true;
  
      }
  </code></pre>