Unknown
Unknown

Reputation: 46831

Stop Visual Studio from Closing Program After Finish

This is probably an easy Visual Studio question, but I couldn't find it on the site.

When I "Start Debugging" a console program, it immediately exits when its finished. Is there any way to have it pause when it ends without putting an explicit pause command at the end of your program?

Upvotes: 8

Views: 9011

Answers (6)

alex tektumanidze
alex tektumanidze

Reputation: 21

In visual studio 2019 you can disable closing automatically after finishing execution.

Debug(menue tab) -> options

Debugging -> general

uncheck "Automatically close the console when debugging stops"

Upvotes: 0

TheVillageIdiot
TheVillageIdiot

Reputation: 40512

yes as @matthew said Console.ReadKey() will wait for your input after executing program, but you can use Console.ReadLine() which will terminate only if <ENTER> key is pressed:

void main()
{
    Console.WriteLine("Hello World!"); //:)
    Console.ReadLine();//this will do the trick.
}

Upvotes: 1

corn&#233;
corn&#233;

Reputation: 798

Add a breakpoint just before the application finishes.

Upvotes: 10

Vadym Stetsiak
Vadym Stetsiak

Reputation: 1970

You can place Console.ReadLine at the end of the program. That will force program to wait for a newline character input. Or you can place breakpoint at the end of the probram.

Upvotes: 6

Sonny Boy
Sonny Boy

Reputation: 8016

Console.ReadKey() should do it. It will pause the execution of your program until a key is pressed on the keyboard.

Upvotes: 1

leppie
leppie

Reputation: 117350

"Run without Debugging" does that, but I guess you want to debug still :)

Upvotes: 3

Related Questions