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.
No comments yet. Be the first to share your thoughts!