Alex Rivera | Logout

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

Asked 2009-02-03T17:59:29.043
30

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

Edit
Report

1 Answer

28

No it won't hog the CPU, it will just pause your thread for at least that long. While your thread is paused, the operating system can schedule another, unrelated thread to make use of the processor.

answered 2009-02-03T18:01:32.113

Your Answer