We have a multi threaded application that uses synchronous methods. Is there a performance difference between the two methods?
public void RunSleep()
{
Thread.Sleep(3000);
}
public void RunTask()
{
var task = Task.Run(() =>
{
Thread.Sleep(3000);
});
task.Wait();
}
Thread.Sleep
is supposed to symbolise an HTTP request.
While I understand that refactoring it to be an asynchronous method would be optimal, is there a benefit to using the second version?
EDIT: to specify, my question was if wrapping a long running and synchronous method in a task results in more efficient multi threading, based on this thread this thread.
Relevant quote:
Use Thread.Sleep when you want to block the current thread.
and
Use Task.Delay when you want a logical delay without blocking the current thread.