예제 #1
0
        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();
            }
        }
예제 #2
0
 private static extern bool SetServiceStatus(IntPtr handle, ref ServiceStatus serviceStatus);