title: Debugging a Windows Service - Prevent Cannot Start Service
body: <p>Trying to deubg a windows service (removed the need to install, code, install, code, etc..), thought I found the solution</p>
  
  <pre><code>class Program
  {
      static void Main(string[]args) 
      {
          ClientService service = new ClientService();
  
          if (args.Length &gt; 0) 
          {
              Task.Factory.StartNew(service.Main, TaskCreationOptions.LongRunning);
  
              Console.WriteLine("running...");
              Console.ReadLine();
  
          }
          else 
          {
  #if (!DEBUG)
              ServiceBase[]ServicesToRun;
              ServicesToRun = new ServiceBase[]
              {
                  new MyService()
              };
              ServiceBase.Run(ServicesToRun);
  # else
              ServiceBase.Run(service);
          }
  # endif
      }
  }
  </code></pre>
  
  <p>However I'm still getting the error:</p>
  
  <blockquote>
    <p>Cannot start service from the command line or debugger. A windows Service must first be installed(using installutil.exe) and then started with the ServerExplorer, Windows Services Administrative tool or the NET START command.</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/14m0G.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/14m0G.png" alt="enter image description here"></a></p>
  
  <p>Any Ideas what I need to change to avoid the prompt?</p>