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