What is the point of using await in asynchronous methods?

Asked

Viewed 49 times

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>>());
    }
}
  • 1

    Doesn’t that answer anymore? https://answall.com/q/2793/101

  • @Maniero, @Leandro Angelo. My doubt is not necessarily related to the use of asyncand await but the reason to use a await in a method that is declared with async. Why GetGizmosAsync() must be a async whether his behavior appears to be from a synchronous method ?

  • But the behavior is not of synchronous method.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.