0
static async Task Main(string[] args)
{
    var txt = await GetTask();
}

static Task<string> GetTask()
{
    return GetText();
}

static async Task<string> GetText()
{
    await Task.Delay(2000);
    return "result";
}

Is asynchrony breaking in my case? Do I need to make the GetTask async method?

Mohamad Mousheimish
  • 1,641
  • 3
  • 16
  • 48
awp-sirius
  • 59
  • 6

1 Answers1

2

If it's a simple forward, no you don't, if there is a chance something in the code block could go wrong, you would have to handle exceptions with Task.FromException to push the exception onto the task (in the way the async and await pattern would), in which case it's probably easier to just use the async keyword and await the awaitables for a small performance hit of the IAsyncStateMachine.

halfer
  • 19,824
  • 17
  • 99
  • 186
TheGeneral
  • 79,002
  • 9
  • 103
  • 141