ServiceController.ExecuteCommand(Int32) Metódus
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Végrehajt egy egyéni parancsot a szolgáltatáson.
public:
void ExecuteCommand(int command);
public void ExecuteCommand(int command);
member this.ExecuteCommand : int -> unit
Public Sub ExecuteCommand (command As Integer)
Paraméterek
- command
- Int32
Alkalmazás által definiált parancsjelölő, amely jelzi, hogy melyik egyéni parancsot kell végrehajtani. Az értéknek 128 és 256 közöttinek kell lennie, beleértve az értéket is.
Kivételek
Hiba történt egy rendszer API elérésekor.
A szolgáltatás nem található.
Példák
Az alábbi példakód azt mutatja be, hogy a ServiceController.ExecuteCommand(Int32) metódus használatával egyéni parancsokat hajthat végre a SimpleService szolgáltatás példájában.
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
Megjegyzések
Híváskor ExecuteCommanda szolgáltatás állapota nem változik. Ha a szolgáltatás elindult, az állapot megmarad Running. Ha a szolgáltatás leállt, az állapot továbbra is megmarad Stopped, és így tovább. Az egyéni parancs feldolgozásához a szolgáltatásnak felül kell bírálnia a OnCustomCommand metódust, és meg kell adnia egy kezelőt a command paraméter által azonosított parancshoz.