title: Service cannot be started. The service process could not connect to the service controller when start service
body: <p>I create a service like this :</p>
  
  <pre><code>private SocketDataRepository socketRepository = new SocketDataRepository();
          SerivceIPconfigRepository serivceIPconfigRepository=new SerivceIPconfigRepository();
          public AsyncCallback pfnWorkerCallBack;
          private Socket m_mainSocket;
          private Socket[] m_workerSocket = new Socket[25];
          private int m_clientCount = 0;
          private string ipaddress;
          protected override void OnStart(string[] args)
          {
              ServiceIpConfig serviceIpConfig = serivceIPconfigRepository.GetAll().First();
              DrawMapPersian();
              ipaddress = serviceIpConfig.IncomingIP;
              // Check the port value
  
              string portStr = serviceIpConfig.IncomingPort;
              int port = System.Convert.ToInt32(portStr);
              // Create the listening socket...
              m_mainSocket = new Socket(AddressFamily.InterNetwork,
                                        SocketType.Stream,
                                        ProtocolType.Tcp);
              IPEndPoint ipLocal = new IPEndPoint(IPAddress.Any, port);
              // Bind to local IP Address...
              m_mainSocket.Bind(ipLocal);
              // Start listening...
              m_mainSocket.Listen(4);
              // Create the call back for any client connections...
              m_mainSocket.BeginAccept(new AsyncCallback(OnClientConnect), null);
          }
      protected override void OnContinue()
      {
          base.OnContinue();
      }
      protected override void OnStop()
      {
      }
  </code></pre>
  
  <p>As you can see my service listens to a port for incoming data .I also add an installer for my service as you can see here :</p>
  
  <pre><code> [RunInstaller(true)]
      public class MyWindowsServiceInstaller : Installer
      {
          public MyWindowsServiceInstaller()
          {
              var processInstaller = new ServiceProcessInstaller();
              var serviceInstaller = new ServiceInstaller();
  
              //set the privileges
              processInstaller.Account = ServiceAccount.LocalSystem;
  
              serviceInstaller.DisplayName = "My Service";
              serviceInstaller.StartType = ServiceStartMode.Manual;
  
              //must be the same as what was set in Program's constructor
              serviceInstaller.ServiceName = "My Service";
  
              this.Installers.Add(processInstaller);
              this.Installers.Add(serviceInstaller);
          }
      }
  </code></pre>
  
  <p>I install my service using <code>installutil.exe</code> .everything works fine and my service installed and i can see it in list of services .but when i try to start that i got this error :</p>
  
  <p><img src="https://i.stack.imgur.com/gOpHn.jpg" alt="enter image description here"></p>
  
  <p>I check the log event and my error is this: </p>
  
  <pre><code> Provider 
  
     [ Name]  My Service 
  
    - EventID 0 
  
     [ Qualifiers]  0 
  
     Level 2 
  
     Task 0 
  
     Keywords 0x80000000000000 
  
    - TimeCreated 
  
     [ SystemTime]  2014-08-17T15:38:21.000000000Z 
  
     EventRecordID 7526 
  
     Channel Application 
  
     Computer ehsan-PC 
  
     Security 
  
  
  - EventData 
  
     Service cannot be started. The service process could not connect to the service controller 
  </code></pre>
  
  <p>Where is my problem ?</p>