/// <summary> /// Invoked when the service is stopped. /// </summary> protected override void OnStop() { // Update the service state to stop Pending. ServiceStatus serviceStatus = new ServiceStatus(); serviceStatus.dwCurrentState = ServiceState.SERVICE_STOP_PENDING; serviceStatus.dwWaitHint = 100000; SetServiceStatus(ServiceHandle, ref serviceStatus); // write stop to event log eventLog1.WriteEntry("In onStop."); // close the server m_imageServer.onCloseServer(); // Update the service state to Running. serviceStatus.dwCurrentState = ServiceState.SERVICE_STOPPED; SetServiceStatus(ServiceHandle, ref serviceStatus); }