Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
How to contonue program until not press any key in console application
Do
    .
    .
    .
Loop while <press any key>
Posted 23-Dec-12 19:50pm
taghit381
Comments
Sergey Alexandrovich Kryukov at 24-Dec-12 3:39am
   
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)



Advertise | Privacy | Mobile
Web01 | 2.8.140926.1 | Last Updated 24 Dec 2012
Copyright © CodeProject, 1999-2014
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