0

Consider this asynchronous method:

public async Task<Data> AnotherMethodAsync()
{
    var reader = await GetData();
    reeturn Convert(reader);
}

Now I want to call this from another method. If the call is a simple call through or no work is being done after the call, what is the difference between these two examples:

Return Task

public Task<Data> SomeMethodAsync()
{
    return AnotherMotherAsync();
}

Async/Await

public async Task<Data> SomeMethodAsync()
{
    await AnotherMotherAsync();
}

Is the one more correct than the other? Is there any performance considerations?

Michael
  • 3,350
  • 2
  • 21
  • 35
  • If you don't need to await the response then the task should be fire and forget. Use `Task.Run(() => x)` – Kieran Devlin Feb 20 '20 at 13:19
  • Well maybe there are others calling `SomeMethodAsync` which need to await that. – Michael Feb 20 '20 at 13:26
  • @ESG Yes, I think the [MSDN article](https://learn.microsoft.com/en-us/archive/msdn-magazine/2011/october/asynchronous-programming-async-performance-understanding-the-costs-of-async-and-await). Better start reading :) Basically I want to understand what is going on underneath in the two different scenarios. – Michael Feb 20 '20 at 13:30
  • 1
    I have a [blog post on the subject](http://blog.stephencleary.com/2016/12/eliding-async-await.html). – Stephen Cleary Feb 20 '20 at 13:52

0 Answers0