ServiceBase.OnCustomCommand(Int32) 方法

定義

在衍生類別中實作時,當服務控制管理員 (SCM) 傳遞自訂命令給服務時,將執行 OnCustomCommand(Int32)When implemented in a derived class, OnCustomCommand(Int32) executes when the Service Control Manager (SCM) passes a custom command to the service. 指定在具有指定參數值的命令發生時所要執行的動作。Specifies actions to take when a command with the specified parameter value occurs.

protected:
 virtual void OnCustomCommand(int command);
protected virtual void OnCustomCommand (int command);
abstract member OnCustomCommand : int -> unit
override this.OnCustomCommand : int -> unit
Protected Overridable Sub OnCustomCommand (command As Integer)

參數

command
Int32

傳送至服務的命令訊息。The command message sent to the service.

備註

OnCustomCommand可讓您指定除了啟動、停止、暫停和繼續服務以外的其他功能。OnCustomCommand lets you specify additional functionality beyond starting, stopping, pausing and continuing services.

SCM 不會檢查自訂命令,以確認服務是否支援傳入的command參數。The SCM does not examine the custom command to verify whether the service supports the command parameter passed in. 它會將自訂命令直接傳遞給服務。It passes the custom command directly to the service. 如果服務無法辨識command參數,則不會執行任何操作。If the service does not recognize the command parameter, it does nothing.

自訂命令是由ExecuteCommand ServiceController元件中的語句所引發。Custom commands are raised by an ExecuteCommand statement in a ServiceController component. 使用 switch 語句或 if。then 條件,以處理您在服務上定義的自訂命令。Use a switch statement or if..then condition to handle the custom commands you define on your service.

您可以在應用程式中定義或在中OnCustomCommand使用之自訂命令的唯一值是介於128和255之間的值。The only values for a custom command that you can define in your application or use in OnCustomCommand are those between 128 and 255. 低於128的整數對應于系統保留值。Integers below 128 correspond to system-reserved values.

如果屬性為, true則自訂命令(如同所有其他命令)會將專案寫入事件記錄檔,以報告方法執行成功或失敗。 AutoLogIf the AutoLog property is true, custom commands, like all other commands, write entries to the event log to report whether the method execution succeeded or failed.

適用於

另請參閱