Menu

1 / 2

Background processing in .NET 8 with BackgroundService and Channel

DEV Community: csharp·Eduardo Teixeira·about 16 hours ago
#c5AbBBgn
#devtocsharp#devto#dev#queue#worker
Long article (1128 words) — no AI summary yet.
Reading 0:00
15s threshold

This post was originally published in Portuguese on my blog: Processando em segundo plano no .NET 8 com BackgroundService e Channel .

We've all been there: the endpoint receives a request, does something slow (generates a report, sends an email, calls a slow service) and the client sits waiting until it times out. The classic way out is to respond right away and do the work in the background. You can jump straight to a broker like RabbitMQ, but that's often overkill. In .NET 8 you already have what you need at home: BackgroundService and Channel<T> .

The idea

The API doesn't process anything. It registers the job, puts it in a queue and returns 202 Accepted with a Location header. On the other side, a BackgroundService loops reading from the queue and processing one job at a time.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.