protected override void OnStop() { // Update the service state to Start Pending. var serviceStatus = new ServiceStatus { dwCurrentState = ServiceState.SERVICE_START_PENDING, dwWaitHint = 100000 }; SetServiceStatus(ServiceHandle, ref serviceStatus); Program.Host = HostUtils.TerminateHost(Program.Host); // Update the service state to Running. serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING; SetServiceStatus(ServiceHandle, ref serviceStatus); }