pause in console apps

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
 
W

William Stacey [MVP]

Console.WriteLine("Press any key too continue...");
Console.ReadLine();
// continue...
 
P

Petec

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
 
A

Alex Moskalyuk

Have a variable incremented in KeyDown event.
Print out the message "Press any key..."
AforeMentionedVariable = 0;
while (AforeMentionedVariable == 0);
 
J

Jon Skeet [C# MVP]

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.
 
A

Alex Moskalyuk

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top