Download a .NET Worker Service which is written in .NET 6 and configured to run background tasks.
The code has a hosted service example set up which outputs the current time to the
ILogger interface and loops the task every second.
The project also has the
Microsoft.Extensions.Hosting.WindowsServices NuGet package installed. This provides an
AddWindowsService extension method that allows us to run our Worker Service as a Windows Service.
This is the software that will need to be installed onto your machine.
- Visual Studio 2022 17.0.4 or above. It will work with the free community version. Please note, this project will not work with VS 2019.
- .NET 6.0 SDK 6.0.101 or above. Visual Studio 2022 should already have the .NET SDK installed.
Get the application working
These are the steps to get the application working.
- Fill out the source code form. We will send you an email where you can download the source code.
You are now ready to go.
Open the project in Visual Studio
RoundTheCode.WorkerServiceExample.sln in Visual Studio 2022.
Start the project in Visual Studio.
The hosted services will start once the project has been launched. See the console application as it sends information through the
ILogger instance in the hosted service.
Set up the Worker Service as a Windows Service
Watch our video where we setup and run our Worker Service as a Windows Service.
We also document about it in our article on how to use a .NET Worker Service to run background services.