Async Await usage

  • Thread starter Thread starter JuanC_LopGar97
  • Start date Start date
J

JuanC_LopGar97

Guest
Recently I read the "async await" post by msdn. and I understood it. But actually It causes some doubts on me because in that post says:

'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.'

my question is, When I have to use Async? , When is better use a Thread?

But if you think about it, if you have 1000 instructions, It doesn't matter in what order you have to do all of them. in this case async doesn't help (I think).

But if you are just waiting, is completly different, because you can do more stuff. for example waiting for a web service,a data base consult..., because you dont have to do that task, you are just waiting. Making an analogy to the story, Oven, Microwave are in this case a Server, and you dont need warm food personally, because the oven is doing that for you, you don't have to do that task, just wait a result. so, Do I have to use async when the task is not a "local" set of instruction?

Is this correct?

Continue reading...
 
Back
Top