0

https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/

In this MS link,

Cooking breakfast is a good example of asynchronous work that isn't parallel. One person (or thread) can handle all these tasks. Continuing the breakfast analogy, one person can make breakfast asynchronously by starting the next task before the first completes. The cooking progresses whether or not someone is watching it. As soon as you start warming the pan for the eggs, you can begin frying the bacon. Once the bacon starts, you can put the bread into the toaster.

For a parallel algorithm, you'd need multiple cooks (or threads). One would make the eggs, one the bacon, and so on. Each one would be focused on just that one task. Each cook (or thread) would be blocked synchronously waiting for bacon to be ready to flip, or the toast to pop.

one of the example code is

async Task<Toast> MakeToastWithButterAndJamAsync(int number)
{
    var toast = await ToastBreadAsync(number);
    ApplyButter(toast);
    ApplyJam(toast);
    return toast;
}

If async and await doesnot create new thread then where does async method is executed, because async method returns Tasks, Tasks are executed with background thread pool? I'm confused

sticky bit
  • 36,626
  • 12
  • 31
  • 42
Ganesh
  • 144
  • 1
  • 5
  • 4
    Check [this Stephen Cleary's article](https://blog.stephencleary.com/2012/02/async-and-await.html) which should answer your question in detail. I also highly recommend exploring more articles on his blog. You'll learn a lot about async/await, tasks, and asynchronous programming in general. – 41686d6564 stands w. Palestine Mar 28 '20 at 04:22
  • 1
    Asynchronous methods executed on the same single thread. Notice that asynchronous methods mostly used for accessing external resources (databse, webservice etc). When you send request current thread do nothing, but only waiting for the response. So with async-await we can use this thread to execute something else while waiting for the response. – Fabio Mar 28 '20 at 04:27
  • @AhmedAbdelhameed thank you, this post helped me a lot. – Ganesh Mar 28 '20 at 15:00
  • @Fabio So if I write async method for doing some calculation(or kind of related to current application) instead of external resource, this async method is waste instead I should use thread to implement this. Am I right? – Ganesh Mar 28 '20 at 15:01

0 Answers0