-1

Both method makes current function sleep and then continue to execute, but what's the real difference between them? await will requie the method to be async, why not just use Thread.Sleep?

When should not use Thread.Sleep but Task.Delay?

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
Troskyvs
  • 7,537
  • 7
  • 47
  • 115

1 Answers1

-1

Thread.Sleep will cause the OS thread to be suspended until the timer has elapsed.

await Task.Delay will register a callback method that the OS will execute when the timer elapses. Then the method will return an incomplete Task. Allowing the caller to immediately execute something else on this OS thread.

Jeremy Lakeman
  • 9,515
  • 25
  • 29