+ 3

C# async/await or background worker?

I cant find a comparision they both sound similiar.. whats the best strategy for paralel or async tasks?

17th Jun 2017, 4:37 AM
axel
5 Answers
0
As far as I've met them (not by definition, but by experience): Being parallel means to optimize for bites, like taking equal pieces of the process for some threads available, so multiple cores do it faster. However, if there are no further threads available, it still works as a simple sync process. For example there is the Collection::ForEach method, you call it, and your code will not continue, until the loop is ended, and all elements are used by the loop. At the same time, you do not need to know, if the elements are used on the same thread, or in what order, so it can be parallel too, but still a sync call - you wait for it. Asynchronous calls let the code run next without waiting the end of the task, usually providing an object to monitor the async task, named FutureTask or the likes. Async calls are typically scehuled tasks. However, if the main thread handles the scheduler, it's still sync from the point of view of the main thread, but seems async when you request the task to happen some time later. I mean, you register the task for later, and instead of waiting for it the code continues the execution. Async is used in parallel optimization, but not the other way around. A call/process can be both parallel and async, either, or neither.
24th Jun 2017, 2:11 PM
Magyar Dávid
Magyar Dávid - avatar
0
Thanks a lot for the explanation..what about Background worker ? Is it same as async& await or there are situations where you prefer one over other?
24th Jun 2017, 3:19 PM
axel
0
Read the following article. It explains it through examples and in a logical way, also mentioning BackgroundWorker's: https://msdn.microsoft.com/library/hh191443(vs.110).aspx
24th Jun 2017, 3:31 PM
Magyar Dávid
Magyar Dávid - avatar
0
Awesome thank you so much
24th Jun 2017, 8:04 PM
axel
0
Your welcome ;)
24th Jun 2017, 8:06 PM
Magyar Dávid
Magyar Dávid - avatar