pause in console apps

  • Thread starter Thread starter Aaron
  • Start date Start date
A

Aaron

When you run a console app in VS6 it says "Press any key too continue..."
how can i do that in VS.NET2003?

thanks
 
Console.WriteLine("Press any key too continue...");
Console.ReadLine();
// continue...
 
William said:
Console.WriteLine("Press any key too continue...");
Console.ReadLine();
// continue...

Note that Console.ReadLine() only returns on a newline (the enter key), not
any key.


- Pete
 
Have a variable incremented in KeyDown event.
Print out the message "Press any key..."
AforeMentionedVariable = 0;
while (AforeMentionedVariable == 0);
 
Alex Moskalyuk said:
Have a variable incremented in KeyDown event.

Which KeyDown event is that, in a console app?
Print out the message "Press any key..."
AforeMentionedVariable = 0;
while (AforeMentionedVariable == 0);

That's not guaranteed to *ever* finish, unless the variable is volatile
- and even if the variable were volatile, you'd still be taking up 100%
CPU until someone pressed a key. Tight loops like that should (almost)
never be used for that kind of thing - it's what Monitor.Wait/Pulse was
designed for.
 
You're right, my bad. I was just working with textboxes that looked like
consoles and were called consoles (black backgrounds, white characters),
being in fact textboxes. Missed the fact that he asked for Win32 console
app.
 
Back
Top