Skip to main content
5 events
when toggle format what by license comment
Feb 7, 2022 at 17:04 comment added RTD My understanding is that there is some overlap between "async" and "parallel", but they are not equivalent as an asynchronous task may or may not be scheduled for the originating thread, depending on the task scheduler, if it is a background thread from the threadpool. In the provided example that might not be the case, it can be a foreground thread in, say, a console application, but if for some unfortunate reason it were ASP.Net servicing a request, it would be from the threadpool, so it becomes sync over async, blocking a worker thread from re-use.
Feb 7, 2022 at 16:37 comment added Theodor Zoulias @RTD you are right that the docs describe the Task.Run action parameter as "The work to execute asynchronously". But if you see the docs for the Thread constructor, it says: start: "A delegate that represents the methods to be invoked when this thread begins executing". My point is that the term "asynchronous" is used selectively in the docs, even for APIs that do similar things. Both the Task.Run(action) and the new Thread(action).Start() invoke an action on another thread. Would you say that starting a thread is an asynchronous operation? Or that it's an anti-pattern?
Feb 7, 2022 at 15:55 comment added RTD Although, you're right that PLINQ is apparently re-using the originating thread via under-the-hood optimization, and this isn't occurring in the latter example.
Feb 7, 2022 at 15:50 comment added RTD While I agree with some of your assessment here, according to the Microsoft documentation on Task.Run, the action passed to the method is the action to be executed "asynchronously", sans the "async" keyword, The best definition of the sync over async anti-pattern is "when you’re using a blocking wait on an async method, instead of awaiting the results asynchronously. This wastes the thread, causes unresponsiveness (if called from the UI), and exposes you to potential deadlocks." makolyte.com/fixing-the-sync-over-async-antipattern
Feb 7, 2022 at 9:05 history answered Theodor Zoulias CC BY-SA 4.0