Closed uabarahona closed 4 years ago
I don't quite follow. That Task.Run makes the order indeterminate. The main conflict here seems to be trying to use both the console logger and console input at the same time. You'd be better off disabling the console logger and using some other kind of logging if you want to write an interactive console application.
Thanks for the answer, yeah I am probably not using generic host in the correct way to make a interactive console a doc on this could be great! but my main concern is about the order of logs which could not be a big deal.
For example here: https://github.com/aspnet/Extensions/blob/master/src/Hosting/samples/GenericHostSample/ProgramHelloWorld.cs
There is two hosted services and the host is being executing with RunConsoleAsync
but when checking logs we can see the following:
Logs from services are at the beginning while the RunConsoleAsync logs are after that, I was expecting the RunConsoleAsync
to execute at the beginning at all but I could wrong, could you please confirm me this?
RunConsoleAsync is effectively just an alias for Host.RunAsync(). That starts all of the services and then the ConsoleLifetime logs that everything has successfully started. This is the expected behavior.
I could see re-ordering these lines so that the CTL+C log was last. https://github.com/aspnet/Extensions/blob/cda774390962745f07baa11069f46aec489f4c61/src/Hosting/Hosting/src/Internal/ConsoleLifetime.cs#L69-L71
Got it, so ConsoleLifetime makes sure all services are started correctly and only then logs that success. Now it make sense for me.
And yes having CTL+C and the end might be better.
Thanks for all.
This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.
See our Issue Management Policies for more information.
Describe the bug
Hi,
Not sure if I am using the generic host correctly but doing some playing with it I found when using RunConsoleAsync() is the HostedService whose methods are executed first, so I was wondering shouldn't ConsoleLifetime be executed first?
That way I am able to end application before any work on HostedServices happens
To Reproduce
Program.cs
ConsoleApplication.cs
Further technical details