.NET › Generic Host
What does calling host.Run() versus host.RunAsync() do, and when would you use each?
BeginnerAnswer
host.Run() is a blocking call that starts the host and blocks the calling thread until the application shuts down (via a shutdown signal or programmatic stop), suitable for a Program.cs's final statement in most applications. host.RunAsync() returns a Task instead, letting you await it while still doing other async work concurrently, or combine it with other awaited tasks -- useful in more complex startup scenarios where you need additional coordination logic around the host's lifetime.
// Simple, most common case
var host = builder.Build();
host.Run(); // blocks here until shutdown
// More complex: awaiting alongside other async startup logic
await host.StartAsync();
await DoAdditionalSetupAsync();
await host.WaitForShutdownAsync();Real-world example A typical Worker Service Program.cs simply calls host.Run() as its final line, while a more complex hybrid application uses host.RunAsync() combined with additional coordination logic for a custom startup sequence.