Search code examples
c#synchronousthread-sleep

Synchronous method vs Thread.Sleep()


I can't understand the difference between Thread.Sleep() and synchronous methods. Please explain..

Is synchronous method in C# is similar to Thread.Sleep()?.


Solution

  • No, other than Thread.Sleep is a synchronous method.

    A synchronous method is one where the entirety of their functionality happens before returning control to the caller.

    Thread.Sleep is a function which causes the executing thread to block for the specified number of milliseconds (not exactly, but close due to the CPU thread scheduler). It executes synchronously and wouldn't be as useful in an asynchronous method.

    However, saying they are the same thing would be a misnomer, as there are plenty of synchronous methods that are not Thread.Sleep and do not use it either.