ServiceBase.Run ServiceBase.Run ServiceBase.Run ServiceBase.Run Method

Definition

Provides the main entry point for a service executable.

Overloads

Run(ServiceBase) Run(ServiceBase) Run(ServiceBase) Run(ServiceBase)

Registers the executable for a service with the Service Control Manager (SCM).

Run(ServiceBase[]) Run(ServiceBase[]) Run(ServiceBase[]) Run(ServiceBase[])

Registers the executable for multiple services with the Service Control Manager (SCM).

Run(ServiceBase) Run(ServiceBase) Run(ServiceBase) Run(ServiceBase)

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)

Parameters

service
ServiceBase ServiceBase ServiceBase ServiceBase

A ServiceBase which indicates a service to start.

Exceptions

Remarks

Call this overload in the main() function of the service executable to register the service with the Service Control Manager. 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. The service is not started until the Start command is executed.

The ServiceBase.Run method is called in much the same way as Application.Run for Windows Forms applications.

If AutoLog is true, an entry is written to the event log if the service specified by the service parameter fails to start.

See also

Run(ServiceBase[]) Run(ServiceBase[]) Run(ServiceBase[]) Run(ServiceBase[])

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())

Parameters

services
ServiceBase[]

An array of ServiceBase instances, which indicate services to start.

Exceptions

You did not supply a service to start. The array might be null or empty.

Remarks

Call this overload in the main() function of the service executable to register the services with the Service Control Manager. After you call Run(ServiceBase[]), the Service Control Manager issues Start commands, which result in calls to the OnStart methods in the services. The services are not started until the Start commands are executed.

The ServiceBase.Run method is called in much the same way as the Application.Run method for Windows Forms applications.

If AutoLog is true, an entry is written to the event log if any service in the array fails to start.

See also

Applies to