Note Because SpinWait is computationally intensive, it will complete earlier or later depending on your computer's clock speed.
static void Main()
Stopwatch stopwatch = Stopwatch.StartNew();
// CPU is maxed out during this call.
// ... (Try making it much larger to test.)Thread.SpinWait(1000000);
A discussion. Several years ago I tried to determine how to adjust the number of threads optimally for a multiple-core machine. SpinWait was helpful in this task.
Info When I used Thread.Sleep, the experiment did not involve the CPU and so did not yield correct results.
But When I used Thread.SpinLock, the results were correct. SpinLock is necessary to simulate actual CPU usage.
Summary. We looked at Thread.SpinWait found in the System.Threading namespace. If you want to waste electricity and make your computer do a lot of computations, this method is perfect.