I'm creating a simple console application under Windows XP and wondering if there is a way to keep the console window open after the application is run from the Windows run prompt, without putting an endless loop at the end of main(). I want the app to behave like it was run from the run prompt after first typing cmd.
You can simply press Ctrl + F5 instead of F5 to run the built code. Then it will prompt you to press any key to continue. Or you can use this line -> system("pause"); at the end of the code to make it wait until you press any key.
Keep Console Open With the Ctrl + F5 Shortcut in C# The best approach for keeping our console window open after the execution of code is to run it with the Ctrl + F5 shortcut of the Microsoft Visual Studio IDE.
Before the end of your code, insert this line: system("pause"); This will keep the console until you hit a key. It also printed "Press any key to continue . . ." for me.
Start the project with Ctrl + F5 instead of just F5 . The console window will now stay open with the Press any key to continue . . . message after the program exits.
ask the user for input will stop the application flow , i think it was
string x = console.ReadLine();
I think you'll need a second application which invokes the command prompt then tells it to execute your console application.
You can even do it with a single application that when called parameterless invokes the prompt and itself with a parameter that disables this behavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With