This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

Visual Studio
VS 2003+

Stop Console Applications From Closing Immediately

When you develop your first console application, it can be a surprise when you execute your application in debug mode and find that the console closes before you have time to see the results. There are two ways to avoid this.

Start Without Debugging

When you execute a console application in debug mode, the program closes and debugging stops after the final line of code executes. The simplest method to avoid this is to start the application from Visual Studio without using debugging. You do so by selecting "Start Without Debugging" from the Debug menu or by pressing Ctrl-F5. When the program stops executing, you must press a key before the console window closes.

If you use the above method, the debugger is not attached to the running program so monitoring of variable values and program flow is not possible. If you need to debug but want the program to remain open, add the following line to the end of the code. This waits for you to press Enter before closing.

16 July 2006