ServiceBase.OnCustomCommand(Int32) 方法
定义
在派生类中实现时,OnCustomCommand(Int32) 于“服务控制管理器”(SCM) 向服务传递自定义命令时执行。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 .。。用于处理在服务上定义的自定义命令的条件。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.
如果 AutoLog 属性为 true ,则自定义命令(如所有其他命令)将条目写入事件日志,以报告方法执行是成功还是失败。If 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.