Are async / wait and return Task the same?

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 a difference between the two?

+4
source share
1 answer

I believe that the first option will wait for the task to complete (not by blocking the thread, but by signing the rest of the method that should be executed when the task is executed, in the style of transition to continuation). The second option will not be. You started and returned the task, but your calling thread will just execute if it does not call .Wait () or anything else.

/ - , Task , , , , .

0

Source: https://habr.com/ru/post/1617579/


All Articles