0

I don't know different Thread.Sleep() and Task.Wait().

public void Start ()
{
    mytask = new Task( ()=> { this.Proccess(); });
    mytask.Start();
}

private void Process()
{
    while(true)
    {
        if( blahblah )
             { process.. }
        else
            {
                Thread.Sleep((int)1000/30);     // name is "A".
                // mytask.Wait( (int)1000/30 );  // name is "B".
            }
    }
}

I was using the C++ Language. Then I used the Sleep() for Thread Context switch.

"A" code is cpu usage is low. "B" code is cpu usage is low.

So "A" and "B" is doing context switch.

What the there different? What I using the code?

abatishchev
  • 98,240
  • 88
  • 296
  • 433

1 Answers1

1

Thread.sleep means the Thread is hanging up and not working.

Task.Wait means wait the Async Threads complete .

MapleStory
  • 628
  • 3
  • 11
  • 22
  • thanks for answer. Is Task.Wait() not hanging up and Async Thread complete? Not hanging up is cpu usage is high. Well, cpu usage is low. I don't understand. – user2334401 Dec 08 '15 at 07:07