SkillAgentSearch skills...

CoordinatedBackgroundService

An implementation of IHostedService which separates initialization from execution

Install / Use

/learn @MV10/CoordinatedBackgroundService
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

CoordinatedBackgroundService NuGet

Repository for my CoordinatedBackgroundService package and the related article:

2020-Jan-05: Lifecycle of Generic Host Background Services

Purpose

A replacement for the .NET IHostedService which provides a separate initialization phase, distinct from the service execution phase. This can prevent startup race conditions in dependent services. Detailed examples are available in the article.

Usage

Create and host a class which derives from the CoordinatedBackgroundService base class, which is in the Microsoft.Extensions.Hosting namespace. At a minimum, you probably want to override InitializingAsync and ExecuteAsync, and maybe StoppingAsync.

If your service needs to initiate application shutdown, inject IHostApplicationLifetime into the constructor and call StopApplication where necessary.

Since these services execute on unmonitored threads, it is absolutely necessary to handle all exceptions. Any unhandled exceptions will immediately terminate the application.

View on GitHub
GitHub Stars4
CategoryDevelopment
Updated4mo ago
Forks3

Languages

C#

Security Score

82/100

Audited on Nov 24, 2025

No findings