title: Windows Service start then stops immediately
body: <p>I've created a windows service that creates a Form in which a tool strip icon is created to manage a socket. I'm able to install through an installer created in Visual Studio, but when I go to Services and start my service it gives me an error saying it started and stopped immediately. </p>
  
  <p>Here's the service code:</p>
  
  <pre><code>public Service()
      {
          InitializeComponent();
      }
  
      protected override void OnStart(string[] args)
      {
          base.OnStart(args);
  
          ServiceName = "WizardServer";
          CanPauseAndContinue = false;
          CanHandleSessionChangeEvent = true;
          CanStop = true;
  
          Application.EnableVisualStyles();
          Application.SetCompatibleTextRenderingDefault(false);
  
          try
          {
              connectionHandler = new ConnectionHandler();  
              serviceThread = new System.Threading.Thread(new ThreadStart(serviceTarget));
              alive = true;
              serviceThread.Start();
          }
          catch {}
      }
  
      private void serviceTarget()
      {
          Application.Run(new Form1(connectionHandler));
  
          while (alive) 
          {
              Thread.Sleep(10000);
          }
      }
  
      protected override void OnStop()
      {
          base.OnStop();
  
          try
          {
              connectionHandler.stop();
          }
          catch {}
  
          serviceThread.Abort();
  
          alive = false;
          Stop();
      }
  </code></pre>
  
  <p>PS: I've tested the form and it works just fine.</p>