How to create a service in .NET Core?
19
26-Feb-2026
Updated on 26-Feb-2026
Amrith Chandran
26-Feb-2026Creating a service in .NET Core depends on what kind of service you need. Most commonly, this means creating a Worker Service (background service), which can run as a Windows Service or Linux daemon.
Below is the standard way to create a service in modern .NET (Core / .NET 6+).
Method 1: Create a Worker Service
This is the official way using the Worker Service template in .NET.
1: Create a New Worker Service Project
Using .NET CLI:
Or in Visual Studio:
2: Understand the Generated Files
The template creates:
Program.csWorker.csExample
Worker.cs:BackgroundServiceis used to implement long-running tasks.3: Register the Service (Program.cs)
In .NET 6+:
4: Run the Service
Run as Windows Service
To run as a real Windows Service:
Install NuGet Package
Update Program.cs
Publish
Register Service
Then start: