Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ctrl+C does not stop synchronous Execute when called from the HostBuilder.RunCommandLineApplicationAsync #449

Closed
lucastheisen opened this issue Mar 24, 2021 · 3 comments
Labels
bug closed-stale This issue is closed because it went stale and there was no action planned. It can be reopened. help wanted We would be willing to take a well-written PR to help fix this. stale

Comments

@lucastheisen
Copy link
Contributor

Describe the bug
Our application has many subcommands, some of which are synch, some async. We use the HostBuilder to initialize all the DI objects and as such, RunCommandLineApplicationAsync appears to be running the application async regardless of whether or not the eventual commmand is sync or async. From what i have gathered on other related issues if run async, then application shutdown is waited on before exit after Ctrl+C. I am not explicitly supplying a cancellation token, but the CommandLineLifetime appears to prevent immediate shutdown, regardless

To Reproduce
Use HostBuilder

        public static async Task<int> Main(string[] args)
            => return await new HostBuilder()
                // more initialization here
                .RunCommandLineApplicationAsync<Program>(args)
                .ConfigureAwait(false);

With a synch subcommand

        protected int OnExecute(CommandLineApplication app)
            => longRunningSynchronousWork();

Start, then press Ctrl+C

Expected behavior
Ctrl+C immediately stops application

Additional context
This can be worked around with:

        protected int OnExecute(CommandLineApplication app)
        {
            Console.CancelKeyPress += (_, e) => e.Cancel = false;

            return longRunningSynchronousTask();
        }
@natemcmaster natemcmaster added the help wanted We would be willing to take a well-written PR to help fix this. label May 15, 2021
@natemcmaster
Copy link
Owner

Marking as help-wanted. If you have good way to fix this, feel free to send a pull request.

@github-actions
Copy link

This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please comment if you believe this should remain open, otherwise it will be closed in 14 days. Thank you for your contributions to this project.

@github-actions github-actions bot added the stale label May 16, 2022
@github-actions
Copy link

Closing due to inactivity.
If you are looking at this issue in the future and think it should be reopened, please make a commented here and mention natemcmaster so he sees the notification.

@github-actions github-actions bot added the closed-stale This issue is closed because it went stale and there was no action planned. It can be reopened. label May 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug closed-stale This issue is closed because it went stale and there was no action planned. It can be reopened. help wanted We would be willing to take a well-written PR to help fix this. stale
Projects
None yet
Development

No branches or pull requests

2 participants