Ctrl+C not captured when waiting on Console.ReadKey
See original GitHub issueI’m building an interactive console app where arguments can be specified on the command line, or the user will be asked to enter the argument values at run-time.
According to the docs, ConsoleAppFramework handles the cancel event? I’ve set the shutdown time to zero so I’d expect the app to terminate immediately on Ctrl+C even tho we’re waiting on the user.
I’ve tried handling Ctrl+C myself by setting Console.TreatControlCAsInput = true
and checking the returned key info. This seems to work in debug but not when running in release mode.
Any help would be appreciated.
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How do I trap Ctrl+C (SIGINT) in a C# console app?
When the user presses Ctrl + C the code in the delegate is run and the program exits. This allows you to perform...
Read more >Console.CancelKeyPress Event (System)
Occurs when the Control modifier key (Ctrl) and either the C console key (C) or the Break key are pressed simultaneously (Ctrl+C or...
Read more >Prevent console from terminate by ctrl-C or multi press ...
I have a console process in c# that uses Control-C to 'trip' an event ... ReadLine() 'While function is running, this will 'start...
Read more >Handling CTRL-C in .NET Console Applications
By default, pressing CTRL-C while a console application is running will cause it to terminate. If we want to prevent this we can...
Read more >Console application that exit on Ctrl-C (ready for Docker)
Console application that exit on Ctrl-C (ready for Docker) - Ctrl-C-Console-App.md. ... ReadKey do not work as expected under Docker container environment.
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
I’ve found bug of console-lifetime handling please wait a moment, I’ll fix it.
Thanks, I’ll check it out.