Hang when calling start/stop on IHost
See original GitHub issueThe program below appears to hang after logging the application is shutting down message and I don’t understand why. The OnProcessExit event appears to be waiting here https://github.com/aspnet/Extensions/blob/master/src/Hosting/Hosting/src/Internal/ConsoleLifetime.cs#L79 but I don’t know why that would be or if that is a problem or just a red herring.
public class Program
{
public static async Task Main(string[] args)
{
var host = CreateHostBuilder(args).Build();
await host.StartAsync();
await host.StopAsync();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices(services => services.AddHostedService<Worker>());
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:36 (17 by maintainers)
Top Results From Across the Web
Are Asp.Net Core 3.1 IHost implementations designed to ...
Technically, yes, they are restartable, or at least, there's nothing technically stopping you from calling StartAsync again.
Read more >NET Generic Host
When a host starts, it calls IHostedService.StartAsync on each implementation of IHostedService registered in the service container's ...
Read more >Diagnosing an ASP.NET Core hard crash
I start the ASP.NET Core app in a separate thread (although that's probably unnecessary anyway, now that I think about it) calling IHost....
Read more >ASP.NET Core IHostedService, BackgroundService and error ...
The StopAsync method is called in the opposite order on application shutdown. ... NET Core runtime waits for the first StartAsync to finish...
Read more >Controlling IHostedService execution order in ASP. ...
In this post I show how to control whether your IHostedService runs before or after the GenericWebHostService starts the Kestrel HTTP ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah, we need to look at designing a real solution to this problem now.
It has nothing to do with background services. It’s all about the code in Program.cs that starts the host.