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.

Ctrl+C not captured when waiting on Console.ReadKey

See original GitHub issue

I’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:closed
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

neuecccommented, Jun 20, 2022

I’ve found bug of console-lifetime handling please wait a moment, I’ll fix it.

jamesfostercommented, Jun 22, 2022

Thanks, I’ll check it out.

Read more comments on GitHub >

github_iconTop 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) - ... ReadKey do not work as expected under Docker container environment.
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 Post

No results found

github_iconTop Related Hashnode Post

No results found