Visual Studio 2010 "Press any key to continue ...". does not show

"Press any key to continue." No lines are displayed on the console when my application completes execution.

I know that this prompt should be displayed in the "start without debugging" mode, but it is not! As soon as I enter some parameter and press enter, the console window closes without showing the result ...

What should I do so that the console application asks me for any key when it finishes execution?

+6
source share
3 answers

According to the comments on the VS2010 error , you should get the desired behavior if you set the project subsystem property to "console". Go to "Project"> "Properties"> in a new window, select "Configuration Properties"> "Object"> "System"> "Properties". SubSystem must be set to Console (/ SUBSYSTEM: CONSOLE)

+15
source

In your main method, add a Try...Catch...Finally block, as shown:

This will ensure that all exceptions you receive are displayed and that the user will need to take measures to close the command window.

 try { // Your existing code } catch (Exception e) { // Log the exception, eg: Console.WriteLine(e.ToString()); } finally { Console.WriteLine ("Please press any key to close"); Console.ReadKey(); } 
-1
source

Please clarify your question. Without a clue of what you are trying to do, it is difficult to help.

In any case, if you are trying to create a console application, you may have forgotten to add the following lines at the end of your code:

 Console.Write('Press any key to continue...'); Console.ReadKey(); 
-1
source

Source: https://habr.com/ru/post/907839/


All Articles