Suppose to have a service library with a method like this
public async Task<Person> GetPersonAsync(Guid id) {
return await GetFromDbAsync<Person>(id);
}
Following the best practices for the SynchronizationContext is better to use
public async Task<Person> GetPersonAsync(Guid id) {
return await GetFromDbAsync<Person>(id).ConfigureAwait(false);
}
But when you have only one operation (I think) is better to return the Task directly. See At the end of an async method, should I return or await?
public Task<Person> GetPersonAsync(Guid id) {
return GetFromDbAsync<Person>(id);
}
In this last case you can't use ConfigureAwait(false) because the method is not awaited.
What is the best solution (and why)?
await
. – Patryk ĆwiekTask
to complete - if that code isasync
, it can decide whether to capture context whenawait
ing the result. – Damien_The_Unbeliever