protected override void OnStart(string[] args) { ServiceStatus serviceStatus = new ServiceStatus(); serviceStatus.dwCurrentState = ServiceState.SERVICE_START_PENDING; try { serviceStatus.dwWaitHint = 100000; SetServiceStatus(this.ServiceHandle, ref serviceStatus); updateAll(); serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING; SetServiceStatus(this.ServiceHandle, ref serviceStatus); base.OnStart(args); } catch (Exception e){ wLog.WriteIntoFile("Failure detected. Stopping the program."); wLog.WriteIntoFile("Retrieving cause:"); wLog.WriteIntoFile(e.Message); wLog.WriteIntoFile(e.StackTrace); serviceStatus.dwCurrentState = ServiceState.SERVICE_STOPPED; Stop(); } }
private static extern bool SetServiceStatus(IntPtr handle, ref ServiceStatus serviceStatus);