dotnet-worker-services

Build .NET worker services with BackgroundService patterns and lifecycle management.

8|Updated Mar 29, 2026
One-click install
npx skills add https://github.com/Postpartum-genushyacinthus29/dotnet-skills --skill dotnet-worker-services-postpartum-genushyacinthus29
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-worker-services
Source: https://github.com/Postpartum-genushyacinthus29/dotnet-skills/tree/main/skills/dotnet-worker-services
Command: npx skills add https://github.com/Postpartum-genushyacinthus29/dotnet-skills --skill dotnet-worker-services-postpartum-genushyacinthus29

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

dotnet-worker-services helps developers implement robust .NET worker services using BackgroundService patterns, covering lifecycle, hosting, health checks, and graceful shutdown to ensure reliable background processing.

Core Features & Use Cases

  • BackgroundService-based workers with proper startup/shutdown semantics and cancellation handling.
  • Scoped dependency patterns to safely resolve DbContext and other services per unit of work.
  • Health checks, readiness/liveness, and windowed shutdown patterns for resilient production workloads.
  • Event-driven, queue-based, and timer-based execution patterns with guidance and anti-patterns.

Quick Start

Create a basic worker by deriving from BackgroundService, implementing ExecuteAsync with cancellation support and a periodic timer.

Frequently Asked Questions about dotnet-worker-services

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement a .NET BackgroundService with proper cancellation support?

To implement a .NET BackgroundService, derive from the base class and override ExecuteAsync with cancellation support, using a periodic timer or loop that respects the CancellationToken for safe background processing.

What is the best way to resolve scoped dependencies like DbContext in a .NET worker service?

The best way to resolve scoped dependencies like DbContext in a .NET worker service is using scoped dependency patterns, creating a scope per unit of work to safely resolve services without captive dependency lifetime issues.

How do I handle graceful shutdown in .NET worker services?

Handle graceful shutdown in .NET worker services by implementing windowed shutdown patterns and proper lifecycle management, ensuring cancellation tokens propagate correctly to stop long-running tasks safely during hosting termination.

Can I add health checks and readiness probes to a .NET background worker?

Yes, you can add health checks and readiness probes to a .NET background worker by configuring health checks for liveness and readiness, enabling observability for resilient production workloads and monitoring.

What execution patterns are available for .NET worker services?

Available execution patterns for .NET worker services include event-driven, queue-based, and timer-based execution, with guidance on anti-patterns to avoid when building long-running background services and hosted workers.

Why does my .NET background service hang during application shutdown?

A .NET background service hangs during application shutdown when ExecuteAsync blocks without checking the CancellationToken, preventing graceful shutdown; implementing cancellation-safe loops and windowed shutdown patterns resolves this issue.