HiveBrain v1.2.0
Get Started
← Back to all entries
snippetcsharpCritical

How to stop C# console applications from closing automatically?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
closinghowfromapplicationsconsolestopautomatically

Problem

My console applications on Visual Studio are closing automatically once the program finishes the execution. I'd like to "pause" the applications at the end of their execution so that I can easily check the output. How can I achieve that?

Solution

Update:

As of Visual Studio 2017, there's a built-in option in the IDE at:

Tools > Options > Debugging > Automatically close the console when debugging stops


Unchecking it will automatically pause the application at the end of the execution, allowing you the easily check its output without having to add extra code to your application.

There are two ways;
Console.ReadLine();


ReadLine() waits for ↩

or
Console.ReadKey();


ReadKey() waits for any key (except for modifier keys).

Code Snippets

Tools > Options > Debugging > Automatically close the console when debugging stops

Context

Stack Overflow Q#11512821, score: 663

Revisions (0)

No revisions yet.