There are two methods
public async Task T1()
{
await Task.Run(() => /*do something here*/);
}
public Task T2()
{
return Task.Run(() => /*do something here*/);
}
Is there any difference between them?
There are two methods
public async Task T1()
{
await Task.Run(() => /*do something here*/);
}
public Task T2()
{
return Task.Run(() => /*do something here*/);
}
Is there any difference between them?
I believe the first variant will wait for the task to finish (not by blocking the thread, but by signing the rest of the method up to be executed when the task is done, in the Continuation Passing Style). The second option won't. You've started and returned a task, but your calling thread will just carry on unless it calls .Wait() or something.
The async/await stuff is just syntactic sugar around re-writing methods using Task and the continuation passing style, though the result is typically complex enough that you wouldn't do it by hand.