This article doesn't apply to hosted services in .NET. For the latest content on Windows services using Microsoft.Extensions.Hosting.BackgroundService and the Worker Service template, see:
After a service is installed, it must be started. Starting calls the OnStart method on the service class. Usually, the OnStart method defines the useful work the service will perform. After a service starts, it remains active until it is manually paused or stopped.
Services can be set up to start automatically or manually. A service that starts automatically will be started when the computer on which it is installed is rebooted or first turned on. A user must start a service that starts manually.
Note
By default, services created with Visual Studio are set to start manually.
There are several ways you can manually start a service — from Server Explorer, from the Services Control Manager, or from code using a component called the ServiceController.
You set the StartType property on the ServiceInstaller class to determine whether a service should be started manually or automatically.
In the designer, click the service installer for the service you are working with.
In the Properties window, set the StartType property to one of the following:
To have your service install
Set this value
When the computer is restarted
Automatic
When an explicit user action starts the service
Manual
Tip
To prevent your service from being started at all, you can set the StartType property to Disabled. You might do this if you are going to reboot a server several times and want to save time by preventing the services that would normally start from starting up.
Note
These and other properties can be changed after your service is installed.
There are several ways you can start a service that has its StartType process set to Manual — from Server Explorer, from the Windows Services Control Manager, or from code. It is important to note that not all of these methods actually start the service in the context of the Services Control Manager; Server Explorer and programmatic methods of starting the service actually manipulate the controller.
Start a service from Server Explorer
In Server Explorer, add the server you want if it is not already listed. For more information, see How to: Access and Initialize Server Explorer-Database Explorer.
Expand the Services node, and then locate the service you want to start.
Right-click the name of the service, and then select Start.
Start a service from Services
Open the Services app.
Select your service in the list, right-click it, and then select Start.
Start a service from code
Create an instance of the ServiceController class, and configure it to interact with the service you want to administer.
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET
feedback
.NET
is an open source project. Select a link to provide feedback:
Understand and implement dependency injection in an ASP.NET Core app. Use ASP.NET Core's built-in service container to manage dependencies. Register services with the service container.