protected override void OnStart(string[] args) { //these lines must remain at the beginning of this function ServiceStatus serviceStatus = new ServiceStatus { dwCurrentState = ServiceState.SERVICE_START_PENDING, dwWaitHint = 100000 }; SetServiceStatus(ServiceHandle, ref serviceStatus); SyncEventLog.WriteEntry("Starting Service", EventLogEntryType.Information, EventId++); //end of beginning lines System.Timers.Timer SyncTimer = new System.Timers.Timer { Interval = 10000 // 10 seconds }; SyncTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimer); SyncTimer.Start(); //these lines must remain at the end of this function. serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING; SetServiceStatus(ServiceHandle, ref serviceStatus); }
protected override void OnStop() { //these lines must remain at the beginning of this function ServiceStatus serviceStatus = new ServiceStatus { dwCurrentState = ServiceState.SERVICE_STOP_PENDING, dwWaitHint = 100000 }; SetServiceStatus(ServiceHandle, ref serviceStatus); SyncEventLog.WriteEntry("Stopping Service", EventLogEntryType.Information, EventId++); //end of beginning lines // close all running tasks //these lines must remain at the end of this function. serviceStatus.dwCurrentState = ServiceState.SERVICE_STOPPED; SetServiceStatus(ServiceHandle, ref serviceStatus); }