Description
Looping structures are key design structures use in programming languages.The ability to repeat code is a powerful tool and can save many lines of code.An infinite loop wil use 100% of the CPU.Suggest two(2) action that you can take prevent problem
Explanation & Answer
while(true){//add whatever break condition here}
But this will trash the CPU performance. This execution thread will take as much as possible from CPU's power.
What is the best way to lower the impact on CPU? Adding some Thread.Sleep(n)
should do the trick, but setting a high timeout value for Sleep()
method may indicate an unresponsive application to the operating system.
Let's say I need to perform a task each minute or so in a console app. I need to keep Main()
running in an "infinite loop" while a timer will fire the event that will do the job. I would like to keep Main()
with the lowest impact on CPU.
What methods do you suggest. Sleep()
can be ok, but as I already mentioned, this might indicate an unresponsive thread to the operating system.
Review
Review
24/7 Homework Help
Stuck on a homework question? Our verified tutors can answer all questions, from basic math to advanced rocket science!
Similar Content
Related Tags
The Da Vinci Code
by Dan Brown
The Subtle Art of Not Giving a F*ck
by Mark Manson
Jane Eyre
by Charlotte Brontë
Dr Jekyll And Mr Hyde
by Robert Louis Stevenson
The President is Missing
by James Patterson, Bill Clinton
Hidden Figures
by Margot Lee Shetterly
Ezperanza Rising
by Pam Muñoz Ryan
Crippled America
by Donald J Trump