title: C# Running console application as windows service - The service didn't respond error
body: <p>I'm trying to run some console app as windows service, I followed <a href="https://stackoverflow.com/questions/7764088/net-console-application-as-windows-service">this question</a>, and I made a few changes to make it fit to my app.</p>
  
  <p>My main code looks like that:</p>
  
  <pre><code>public static class Program
  {
      public class Service : ServiceBase
      {
  
          public Service(string serviceName)
          {
              this.ServiceName = serviceName;
          }
  
          protected override void OnStart(string[] args)
          {
              Program.Start(args);
          }
  
          protected override void OnStop()
          {
              Program.Stop(this.ServiceName);
          }
      }
      #endregion
  
      static void Main(string[] args)
      {
          if (!Environment.UserInteractive)
              // running as service
              using (var service = new Service("TestService"))
                  ServiceBase.Run(service);
          else
          {
              // running as console app
              Start(args);
          }
      }
  
      private static void Start(string[] args)
      {
          while(true)
          {
              //DO SOMTHING
          }
      }
  
      private static void Stop(string serviceName)
      {
          //Writing to log that 'serviceName' stopped
      }
  }
  </code></pre>
  
  <p>I tried to run the following console app as a service, by using the following steps:</p>
  
  <p>1) Use the command: sc create ServiceTestName123 binPath= "PATH TO THE EXE FILE IN THE PROJECT DEBUG FOLDER".</p>
  
  <p>2) Use the command: sc start ServiceTestName123 "parameter1".</p>
  
  <p>And I got an error:
  "StartService FAILED 1053:
  The service did not respond to the start or control request in a timely fashion"</p>
  
  <p>I read about the error in the internet and found out that I can try to solve this problem by running the start function with another thread, so I updated the OnStart function to the following function:</p>
  
  <pre><code>protected override void OnStart(string[] args)
  {
      Thread t = new Thread(() =&gt; Program.Start(args));
      t.Start();
  }
  </code></pre>
  
  <p>After trying to re-create the service (delete the old one and create the service again with the new OnStart function) and re-run it I got the same error.</p>
  
  <p>By the way, when I ran this code as console app it worked properly.</p>
  
  <p>Could someone please explaing me what am I doing wrong?</p>
  
  <p>Thanks a lot. </p>