Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET
How to contonue program until not press any key in console application
Loop while <press any key>
Posted 23-Dec-12 20:50pm
Sergey Alexandrovich Kryukov at 24-Dec-12 3:39am
What was wrong with just reading on System.Console? :-)

1 solution

Rate this: bad
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...");
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).

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

  Print Answers RSS
0 Peter Leow 315
1 Mika Wendelius 275
2 CHill60 190
3 TheRealSteveJudge 184
4 Abhinav S 170
0 Sergey Alexandrovich Kryukov 8,613
1 OriginalGriff 6,546
2 Peter Leow 3,897
3 Zoltán Zörgő 3,456
4 Richard MacCutchan 2,472

Advertise | Privacy | Mobile
Web02 | 2.8.150123.1 | Last Updated 24 Dec 2012
Copyright © CodeProject, 1999-2015
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