HostedService StartAsync Block Fix

Published: May 15, 2026 · By Kumar Kunal

TL;DR

Don't await long tasks in StartAsync. Fire and forget or use BackgroundService.

The Error

App hangs on startup. Never reaches app.Run()

Root Cause

IHostedService.StartAsync must return quickly. You're doing await LongInit()

Fix

public Task StartAsync(CancellationToken ct)
{
    _ = Task.Run(() => LongInit(), ct);
    return Task.CompletedTask;
}

Or inherit BackgroundService and use ExecuteAsync.

Found this helpful?

Master C# with our complete course. Real apps, real skills, job-ready in 2 hours.

Share this fix: Twitter LinkedIn

Comments on HostedService StartAsync Block Fix (0)

No comments yet. Be the first to share your thoughts!