What is the impact of Thread.Sleep(1) in C#?
c#, multithreading
Solution
As stated, your loop will not hog the CPU.
But beware: Windows is not a real-time OS, so you will not get 1000 wakes per second from Thread.Sleep(1). If you haven't used timeBeginPeriod to set your minimum resolution you'll wake about every 15 ms. Even after you've set the minimum resolution to 1 ms, you'll still only wake up every 3-4 ms.
In order to get millisecond level timer granularity you have to use the Win32 multimedia timer (C# wrapper).
Problem
In a windows form application what is the impact of calling `Thread.Sleep(1)` as illustrated in the following code: ``` public Constructor() { Thread thread = new Thread(Task); thread.IsBackground = true; thread.Start(); } private void Task() { while (true) { // do something Thread.Sleep(1); } } ``` Will this thread hog all of the available CPU? What profiling techniques can I use to measure this Thread's CPU usage ( other than task manager )?