2
Studying on asynchronous/synchronous operations one point was not clear, which would be the use of the await
in methods async
as in this example found on MS’s own website.
If the method GetGizmosAsync()
is declared asynchronous what is the sense of using a await
in httpClient.GetAsync(uri)
would not be better than GetGizmosAsync()
was already declared without the async
?
public async Task<List<Gizmo>> GetGizmosAsync()
{
var uri = Util.getServiceUri("Gizmos");
using (HttpClient httpClient = new HttpClient())
{
var response = await httpClient.GetAsync(uri);
return (await response.Content.ReadAsAsync<List<Gizmo>>());
}
}
Doesn’t that answer anymore? https://answall.com/q/2793/101
– Maniero
@Maniero, @Leandro Angelo. My doubt is not necessarily related to the use of
async
andawait
but the reason to use aawait
in a method that is declared withasync
. WhyGetGizmosAsync()
must be aasync
whether his behavior appears to be from a synchronous method ?– JcSaint
But the behavior is not of synchronous method.
– Maniero