I usually use do
and while
to pause the console. Then, if necessary, the console should resume if you press a specific key.
Example
do
{
/* while (!Console.KeyAvailable) //Continue if pressing a Key press is not available in the input stream
{
//Do Something While Paused
}
*/
} while (Console.ReadKey(true).Key != ConsoleKey.Escape); //Resume if Escape was pressed
If you leave this as //Do Something While Paused
, the console will only resume if the Esc key was pressed doing nothing while paused.
However, if you would not like the console application to resume, you can use while (true);
instead of while (Console.ReadKey(true).Key != ConsoleKey.Escape);
Example
do
{
//break; //Resume
} while (true); //Continue while True (Always True)
Notice: The console application will pause because by doing do { } while (Condition);
you are simply telling the console application that you are doing something. So, the console application will wait for the operation to execute. Then, normally close when there's nothing to do.
Notice: The while
is used to loop. So, the application will not close unless the condition becomes false.
Thanks,
I hope you find this helpful :)