0

I have a console application I'm developing that can be ran a few ways during development.

1. From the IDE in debug (Debugger.IsAttached):

Which gives me a command window that pops up blank and catches keypresses that I wait for using key = Console.ReadKey();. Using this I can cleanly shutdown the console app by pressing the ESC key and do cleanup when it shuts down. It outputs the Console.WriteLine() text to the Output window in the IDE.

2. From the command line in a "Command Prompt" Window:

Which gives me the output for my Console.WriteLine() calls to the same "Command Prompt" window. It does not seem to catch the ESC key being pressed and the only way I can get the app to stop is to press Ctrl+C. This kills the application instantly and does not process the cleanup code I want to run before the app exits.

Is it possible to somehow exit the application when not debugging with the IDE (running as a compiled application in a command prompt)? I would like to have the second example above to be able to shutdown like the first if possible.

Arvo Bowen
  • 4,524
  • 6
  • 51
  • 109

0 Answers0