ServiceBase.Run 方法

定義

提供服務可執行檔的主要進入點。Provides the main entry point for a service executable.

多載

Run(ServiceBase)

使用服務控制管理員 (SCM) 登錄服務的可執行檔。Registers the executable for a service with the Service Control Manager (SCM).

Run(ServiceBase[])

使用服務控制管理員 (SCM) 登錄多個服務的可執行檔。Registers the executable for multiple services with the Service Control Manager (SCM).

Run(ServiceBase)

使用服務控制管理員 (SCM) 登錄服務的可執行檔。Registers the executable for a service with the Service Control Manager (SCM).

public:
 static void Run(System::ServiceProcess::ServiceBase ^ service);
public static void Run (System.ServiceProcess.ServiceBase service);
static member Run : System.ServiceProcess.ServiceBase -> unit
Public Shared Sub Run (service As ServiceBase)

參數

service
ServiceBase

ServiceBase,表示要啟動的服務。A ServiceBase which indicates a service to start.

例外狀況

servicenullservice is null.

備註

在服務可執行檔main()的函式中呼叫這個多載,以向服務控制管理員註冊服務。Call this overload in the main() function of the service executable to register the service with the Service Control Manager. 在您呼叫Run(ServiceBase)之後,服務控制管理員會發出 Start 命令,這會導致呼叫服務中的OnStart方法。After you call Run(ServiceBase), the Service Control Manager issues a Start command, which results in a call to the OnStart method in the service. 在執行 Start 命令之前,服務不會啟動。The service is not started until the Start command is executed.

方法的呼叫方式與Application.Run Windows Forms 應用程式非常類似。 ServiceBase.RunThe ServiceBase.Run method is called in much the same way as Application.Run for Windows Forms applications.

如果AutoLog servicetrue,則如果參數所指定的服務無法啟動,則會將專案寫入事件記錄檔。If AutoLog is true, an entry is written to the event log if the service specified by the service parameter fails to start.

另請參閱

Run(ServiceBase[])

使用服務控制管理員 (SCM) 登錄多個服務的可執行檔。Registers the executable for multiple services with the Service Control Manager (SCM).

public:
 static void Run(cli::array <System::ServiceProcess::ServiceBase ^> ^ services);
public static void Run (System.ServiceProcess.ServiceBase[] services);
static member Run : System.ServiceProcess.ServiceBase[] -> unit
Public Shared Sub Run (services As ServiceBase())

參數

services
ServiceBase[]

ServiceBase 執行個體的陣列,表示要啟動的服務。An array of ServiceBase instances, which indicate services to start.

例外狀況

您不提供要啟動的服務。You did not supply a service to start. 陣列可能為 null 或空白。The array might be null or empty.

備註

在服務可執行檔main()的函式中呼叫這個多載,以向服務控制管理員註冊服務。Call this overload in the main() function of the service executable to register the services with the Service Control Manager. 在您呼叫Run(ServiceBase[])之後,服務控制管理員會發出啟動命令,這會導致呼叫服務OnStart中的方法。After you call Run(ServiceBase[]), the Service Control Manager issues Start commands, which result in calls to the OnStart methods in the services. 在執行 Start 命令之前,服務不會啟動。The services are not started until the Start commands are executed.

方法的呼叫方式與 Windows Forms 應用程式的Application.Run方法大致相同。 ServiceBase.RunThe ServiceBase.Run method is called in much the same way as the Application.Run method for Windows Forms applications.

如果AutoLogtrue,當陣列中的任何服務無法啟動時,會將專案寫入事件記錄檔。If AutoLog is true, an entry is written to the event log if any service in the array fails to start.

另請參閱

適用於