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.

suggestion: support Ctrl+C handling

See original GitHub issue

When the application is terminated by the user (e.g. presses Ctrl+C), it terminates immediately.

The application may want to do something, for example: kill some child processes it has started.

It is possible to handle this using Console.CancelKeyPress. It would be nicer if this was an API pattern in CommandLineUtils. For example: a CancellationToken gets passed to OnExecuteAsync. This token is canceled when the user terminates the application.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tmdscommented, Apr 6, 2019
1reaction
natemcmastercommented, Jun 28, 2018

Interesting idea. I’m thinking through some implementation ideas and it might be quirky when we get into async land. IIRC, callbacks on CancellationTokenSource.Cancel() should run inline, but wouldn’t it still be possible for the CancelKeyPress event handler terminate before some async continuations finish?

The way we solved this in aspnet and dotnet-watch is that the first CTRL+C invocation begins graceful shutdown and sets ConsoleCancelEventArgs.Cancel to true. The second time CTRL+C is raised we force exit the process. I’m wondering if that would be a good pattern to use by default, or if that should be something users configure.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Need help handling "CTRL-C" signal in my simple shell ...
From other side, in many cases pressing CTRL+C indicated user wants to terminate program, so quitting the program is expected behavior. Share.
Read more >
What to do when Ctrl + C can't kill a process?
If Ctrl + C (SIGINT) doesn't work, try Ctrl + \ (SIGQUIT). Then try Ctrl + Z (SIGTSTP). If that returns you to...
Read more >
Ctrl-C
Ctrl -C is just a way to tell your terminal to send a SIGINT signal to the current process. How that process handles...
Read more >
Write a C program that does not terminate when Ctrl+C is ...
It prints a message “Cannot be terminated using Ctrl+c” and continues execution. We can use signal handling in C for this.
Read more >
Recognizing more `ctrl-` keys in Iex - Elixir Forum
Are “special” characters like tab and ctrl-c handled exclusively by an Erlang server, and somehow Iex's current architecture rules out ...
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