ServiceBase.Run Method (ServiceBase)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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

Namespace:   System.ServiceProcess
Assembly:  System.ServiceProcess (in System.ServiceProcess.dll)

public static void Run(
	ServiceBase service


Type: System.ServiceProcess.ServiceBase

A ServiceBase which indicates a service to start.

Exception Condition

service is null.

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.

.NET Framework
Available since 1.1
Return to top