Click here to Skip to main content
13,143,610 members (31,395 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
How to contonue program until not press any key in console application
Do
    .
    .
    .
Loop while <press any key>
Posted 23-Dec-12 19:50pm
taghit387
Comments
   
What was wrong with just reading on System.Console? :-)
—SA

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

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
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web03 | 2.8.170915.1 | Last Updated 24 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100