Ejemplo n.º 1
0
        protected override void OnStart(string[] args)
        {
            _logger.Info("Starting service");

            // Update the service state to Start Pending.
            ServiceStatus serviceStatus = new ServiceStatus();
            serviceStatus.dwCurrentState = ServiceState.SERVICE_START_PENDING;
            serviceStatus.dwWaitHint = 100000;
            SetServiceStatus(this.ServiceHandle, ref serviceStatus);

            try
            {
                mgr = new Manager();
                mgr.Initialize();

                // Update the service state to Running.
                serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING;
                SetServiceStatus(this.ServiceHandle, ref serviceStatus);
            }
            catch (Exception e)
            {
                _logger.FatalException("Service failed to start", e);

                mgr.Stop();

                // Stop the service
                ServiceController service = new ServiceController(SERVICE_NAME);
                service.Stop();
            }
        }
Ejemplo n.º 2
0
 private static extern bool SetServiceStatus(IntPtr handle, ref ServiceStatus serviceStatus);