No they're not.
dataminers wrote:the two code blocks below are the same
The first one starts a new task to execute
CalculateSomething(5), and then suspends the current thread until that task completes. It then starts another task to execute
The second one starts two tasks to execute
CalculateSomething(8), and then freezes the current thread until both have completed.
If you time both approaches, the
AsParallel code will be roughly twice as fast as the two
await Task.Run(...) calls.
The closest equivalent using
Task.Run would be:
Task t1 = Task.Run(() => CalculateSomething(5));
Task t2 = Task.Run(() => CalculateSomething(8));
await Task.WhenAll(t1, t2);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."