Home Save CPU Utilization In An Empty Loop

Save CPU Utilization In An Empty Loop

Sometimes you need to kill some time by running an empty for or while loop. The only problem is that the CPU utilization will soon reach 100% for a single core CPU or 50% for a duel-core. Oh, my Goodness, it is horrible.

How to solve the problem and protect your/and your users’ CPU? A simple walk around is there. Just write Thread.Sleep(??); inside the loop. In my case, I let it sleep for 500-ms. In this way, the utilization can be reduced to a quite small number.

This post is licensed under CC BY 4.0 by the author.

Using CVS in Visual Studio 2005

Subversion Or CVS

Comments powered by Disqus.