Back to results for “Background Services”
.NET › Background Services

How does a BackgroundService differ from a Worker Service project template, and how do they relate?

Intermediate

Answer

A Worker Service is a full project template (`dotnet new worker`) designed specifically for standalone, non-web background processing applications, built around the Generic Host and typically containing one or more BackgroundService implementations. A BackgroundService itself is just a class you can add to any host-based application (web API, worker service, or console app using the Generic Host) -- the Worker Service template is essentially a minimal host setup optimized for apps that are entirely background processing with no web server component.
dotnet new worker -n MyWorkerService

// Program.cs in a Worker Service template
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddHostedService<Worker>();
var host = builder.Build();
host.Run();
Real-world example A company runs a dedicated Worker Service (no web server at all) for nightly batch report generation, deployed as a standalone container, distinct from their ASP.NET Core web API which also happens to run a lightweight BackgroundService for cache warming.

Common follow-ups: When would you add a BackgroundService to a web app instead of a separate Worker Service?;How does resource isolation differ between the two deployment models?