protected override void OnStop() { // Update the service state to pend ending. ServiceStatus serviceStatus = new ServiceStatus(); serviceStatus.dwCurrentState = ServiceState.SERVICE_STOP_PENDING; serviceStatus.dwWaitHint = 100000; SetServiceStatus(this.ServiceHandle, ref serviceStatus); // Update the service state to Stopped. serviceStatus.dwCurrentState = ServiceState.SERVICE_STOPPED; SetServiceStatus(this.ServiceHandle, ref serviceStatus); }
private static extern bool SetServiceStatus(IntPtr handle, ref ServiceStatus serviceStatus);
protected void OnStart() { // Setting up a timer to trigger every minute. System.Timers.Timer timer = new System.Timers.Timer(); timer.Interval = 60000; timer.Elapsed += new System.Timers.ElapsedEventHandler(this.OnTimer); timer.Start(); // 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); // When the service runs, set the state to 'running'. serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING; SetServiceStatus(this.ServiceHandle, ref serviceStatus); // TODO: Check here that the MQ is still alive. If it isn't, wake it up. // TODO: Check any messages in the queue this.ReceiveMessage(); // TODO: For any messages we find, process them with [FUNCTION TO BE WRITTEN](). }