Click here to Skip to main content
15,896,481 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
How to contonue program until not press any key in console application
Do
    .
    .
    .
Loop while <press any key>
Posted
Comments
Sergey Alexandrovich Kryukov 24-Dec-12 3:39am    
What was wrong with just reading on System.Console? :-)
—SA

1 solution

Hell, no! Your loop is polling and is considered a very bad thing, especially in UI. What you need is this:

C#
System.Console.Write("Press any key...");
System.Console.ReadKey(true);


The ReadKey call is blocking. Your thread will be put in wait state wasting not CPU time, will be waken up only when you actually press a key, all the way from triggering a hardware interrupt in OS kernel (or if you abort the thread or the whole process).

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900