question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hang when calling start/stop on IHost

See original GitHub issue

The 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>());
    }

@Tratcher @davidfowl

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:36 (17 by maintainers)

github_iconTop GitHub Comments

8reactions
analogrelaycommented, Aug 3, 2019

Yeah, we need to look at designing a real solution to this problem now.

2reactions
davidfowlcommented, Apr 19, 2020

It has nothing to do with background services. It’s all about the code in Program.cs that starts the host.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found