ServiceController.ExecuteCommand(Int32) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
서비스에서 사용자 지정 명령을 실행합니다.
public:
void ExecuteCommand(int command);
public void ExecuteCommand (int command);
member this.ExecuteCommand : int -> unit
Public Sub ExecuteCommand (command As Integer)
매개 변수
- command
- Int32
실행할 사용자 지정 명령을 나타내는 애플리케이션 정의 명령 플래그입니다. 값은 128 이상 256 이하여야 합니다.
예외
시스템 API에 액세스할 때 오류가 발생했습니다.
서비스를 찾을 수 없습니다.
예제
다음 코드 예제에서는 서비스 예제에서 사용자 지정 명령을 실행 하는 메서드의 SimpleService 사용을 ServiceController.ExecuteCommand(Int32) 보여 줍니다.
using System;
using System.ServiceProcess;
namespace test_exec_cmnd
{
class Program
{
private enum SimpleServiceCustomCommands { StopWorker = 128, RestartWorker, CheckWorker };
static void Main(string[] args)
{
ServiceController myService = new ServiceController("SimpleService");
myService.ExecuteCommand((int)SimpleServiceCustomCommands.StopWorker);
myService.ExecuteCommand((int)SimpleServiceCustomCommands.RestartWorker);
myService.ExecuteCommand((int)SimpleServiceCustomCommands.CheckWorker);
}
}
}
Imports System.ServiceProcess
Class Program
Private Enum SimpleServiceCustomCommands
StopWorker = 128
RestartWorker
CheckWorker '
End Enum 'SimpleServiceCustomCommands
Shared Sub Main(ByVal args() As String)
Dim myService As New ServiceController("SimpleService")
myService.ExecuteCommand(Fix(SimpleServiceCustomCommands.StopWorker))
myService.ExecuteCommand(Fix(SimpleServiceCustomCommands.RestartWorker))
myService.ExecuteCommand(Fix(SimpleServiceCustomCommands.CheckWorker))
End Sub
End Class
설명
호출 ExecuteCommand할 때 서비스의 상태는 변경되지 않습니다. 서비스가 시작된 경우 상태는 그대로 유지됩니다 Running. 서비스가 중지된 경우 상태는 그대로 유지 Stopped됩니다. 사용자 지정 명령을 처리하려면 서비스에서 메서드를 재정의 OnCustomCommand 하고 매개 변수로 식별된 command 명령에 대한 처리기를 제공해야 합니다.