What is the impact of Thread.Sleep(1) in C#?

Posted by Justin Tanner on Stack Overflow See other posts from Stack Overflow or by Justin Tanner
Published on 2009-02-03T17:59:29Z Indexed on 2010/04/08 17:33 UTC
Read the original article Hit count: 409

Filed under:
|
|

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 )?

© Stack Overflow or respective owner

Related posts about c#

Related posts about multithreading