Where and Why I should use async methods in C#? | Sololearn: Learn to code for FREE!

0

Where and Why I should use async methods in C#?

Hi, today I came across the async methods and I was wondering what was the benefits of using them in practicality. So I thought someone would help me out with professional experience and share their thoughts, thank you!!!

c#

7/11/2021 3:54:27 AM

Sreenesh

3 Answers

New Answer

+5

I just recently posted about this a few days ago. I hope it helps. https://www.sololearn.com/Discuss/2829937/?ref=app

+4

Imagine a C# program that sends a request to example.com and grabs a big image. This might take a few seconds and if you do it synchronously, downloading the image blocks the rest of the program. If you do the download asynchronously it happens in the background and you can do other things while the image is downloading. Imagine a program that does something everytime the user shouts "blerp" into their microphone. You could write this as an asynchronous loop and an asynchronous iterator: await foreach (var blerp of GetBlerps()) { // do stuff } The loop will run everytime a new blerp is shouted. Again, without blocking the rest of the program. You can have many async actions running "in parallel" and it will just work.

+1

Thank you!