Click here to Skip to main content
Sign Up to vote bad
good
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:50
taghit336

Comments
Sergey Alexandrovich Kryukov - 24 Dec '12 - 3:39
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:
 
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
Your Filters
Interested
Ignored
     
0 OriginalGriff 216
1 Sergey Alexandrovich Kryukov 169
2 Tadit Dash 154
3 Richard MacCutchan 145
4 Santhosh G_ 115
0 Sergey Alexandrovich Kryukov 10,338
1 OriginalGriff 7,965
2 CPallini 4,201
3 Rohan Leuva 3,522
4 Maciej Los 3,159


Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 24 Dec 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid