Explain async and await

  • async and await keywords are used for asynchronous operations
  • awaiting a process puts in a separate task and returns the reference to that task.
  • Once complete the runtime makes sure that the process starts execution back from where the await process occurs
  • A method in which an await keyword is used should be marked async
public async Task<string> DoSomething() {
    var res = await httpClient.GetAsync("SOME_GET_API");
    return await res.Content.ReadAsStringAsync();
}
  • async and await keywords are used for asynchronous operations
  • awaiting a process puts in a separate task and returns the reference to that task.
  • Once complete the runtime makes sure that the process starts execution back from where the await process occurs
  • A method in which an await keyword is used should be marked async
public async Task<string> DoSomething() {
    var res = await httpClient.GetAsync("SOME_GET_API");
    return await res.Content.ReadAsStringAsync();
}

Buy Me A Coffee

Found this article helpful? Please consider supporting!

Ram
Ram

I'm a full-stack developer and a software enthusiast who likes to play around with cloud and tech stack out of curiosity. You can connect with me on Medium, Twitter or LinkedIn.

Leave a Reply

Your email address will not be published. Required fields are marked *