Implementing long-running background services
It is common to need long-running background services to perform operations like:
- Performing a task on a regular timed schedule.
- Processing queued messages.
- Performing intense work like building AI and ML models or processing video and images.
In the distant past, on the Windows operating system, to have some code running in the background meant building a Windows Service. For example, the database engine of SQL Server is implemented as a Windows Service. With the move to cross-platform, .NET needs a cross-platform solution to run code in the background.
Background services often do not have a user interface, although they might provide one for the configuration and management of the service.
Building a worker service
Now, let’s build a worker service project so that we can see how we would host a long-running background service:
- Use your preferred code editor to add a new project...