Where and Why I should use async methods in C#? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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!!!

11th Jul 2021, 3:54 AM
Sreenesh
Sreenesh - avatar
3 Answers
+ 5
I just recently posted about this a few days ago. I hope it helps. https://www.sololearn.com/Discuss/2829937/?ref=app
11th Jul 2021, 9:28 AM
David Carroll
David Carroll - avatar
+ 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.
11th Jul 2021, 8:14 AM
Schindlabua
Schindlabua - avatar
+ 1
Thank you!
11th Jul 2021, 8:15 AM
Sreenesh
Sreenesh - avatar