private void ReportServiceStatus(ServiceState state, ServiceAcceptedControlCommandsFlags acceptedControlCommands, int win32ExitCode, uint waitHint) { if (serviceStatus.State == ServiceState.Stopped) { // we refuse to leave or alter the final state return; } serviceStatus.State = state; serviceStatus.Win32ExitCode = win32ExitCode; serviceStatus.WaitHint = waitHint; serviceStatus.AcceptedControlCommands = state == ServiceState.Stopped ? ServiceAcceptedControlCommandsFlags.None // since we enforce "Stopped" as final state, no longer accept control messages : acceptedControlCommands; serviceStatus.CheckPoint = state == ServiceState.Running || state == ServiceState.Stopped || state == ServiceState.Paused ? 0 // MSDN: This value is not valid and should be zero when the service does not have a start, stop, pause, or continue operation pending. : checkpointCounter++; nativeInterop.SetServiceStatus(serviceStatusHandle, ref serviceStatus); if (state == ServiceState.Stopped) { stopTaskCompletionSource.TrySetResult(win32ExitCode); } }
private void ReportServiceStatus(ServiceState state, ServiceAcceptedControlCommandsFlags acceptedControlCommands, int win32ExitCode, uint waitHint) { // Recuso deixar ou alterar o estado final if (serviceStatus.State == ServiceState.Stopped) { return; } serviceStatus.State = state; serviceStatus.Win32ExitCode = win32ExitCode; serviceStatus.WaitHint = waitHint; serviceStatus.AcceptedControlCommands = state == ServiceState.Stopped ? ServiceAcceptedControlCommandsFlags.None // Uma vez que aplicamos o "Parado" como estado final, deixamos de aceitar as mensagens de controle. : acceptedControlCommands; serviceStatus.CheckPoint = state == ServiceState.Running || state == ServiceState.Stopped || state == ServiceState.Paused ? 0 // MSDN: Este valor não é válido e deve ser zero quando o serviço não tiver início, parar, pausar ou continuar a operação pendente. : checkpointCounter++; nativeInterop.SetServiceStatus(serviceStatusHandle, ref serviceStatus); if (state == ServiceState.Stopped) { stopTaskCompletionSource.TrySetResult(win32ExitCode); } }
public ServiceStatus(ServiceType serviceType, ServiceState state, ServiceAcceptedControlCommandsFlags acceptedControlCommands, int win32ExitCode, uint serviceSpecificExitCode, uint checkPoint, uint waitHint) { this.serviceType = serviceType; this.state = state; this.acceptedControlCommands = acceptedControlCommands; this.win32ExitCode = win32ExitCode; this.serviceSpecificExitCode = serviceSpecificExitCode; this.checkPoint = checkPoint; this.waitHint = waitHint; }
private void PerformAction(ServiceState pendingState , ServiceState completedState , System.Action serviceAction , ServiceAcceptedControlCommandsFlags allowedControlCommandsFlags) { statusReportCallback(pendingState, ServiceAcceptedControlCommandsFlags.None, win32ExitCode: 0, waitHint: 3000); try { serviceAction(); statusReportCallback(completedState, allowedControlCommandsFlags, 0, waitHint: 0); } catch { statusReportCallback(ServiceState.Stopped, ServiceAcceptedControlCommandsFlags.None, -1, waitHint: 0); } }