I have a below methods which list customers and do something on this customers with using async/await.
public async Task Execute()
{
var customers = await ListCustomersAsync();
foreach(var customer in customers)
{
//do other things
}
}
private async Task<IEnumerable<Customer>> ListCustomersAsync()
{
return await _db.ListCustomersAsync();
}
Below methods have same purpose with above but only difference is async/await. I did not use async/await but I awaited ListCustomersAsync2() method in Execute2() method.
public async Task Execute2()
{
var customers = await ListCustomersAsync2();
foreach(var customer in customers)
{
//do other things
}
}
private Task<IEnumerable<Customer>> ListCustomersAsync2()
{
return _db.ListCustomersAsync();
}
So what is the difference between this methods? What is the difference between using async/await keywords in ListCustomersAsync method then await this ListCustomersAsync method and not using async/await keywords but still await ListCustomersAsync2 method.
Are this methods works same? Which one has more performance? Which one is suitable for best practices? Which one should I prefer?