Task.Factory.StartNew vs. Parallel.Invoke

后端 未结 3 422
清酒与你
清酒与你 2021-01-31 08:16

In my application I execute from couple of dozens to couple of hundreds actions in parallel (no return value for the actions).

Which approach would be the most optimal:<

3条回答
  •  情书的邮戳
    2021-01-31 09:22

    In the grand scheme of things the performance differences between the two methods is negligible when considering the overhead of actually dealing with lots of tasks in any case.

    The Parallel.Invoke basically performs the Task.Factory.StartNew() for you. So, I'd say readability is more important here.

    Also, as StriplingWarrior mentions, the Parallel.Invoke performs a WaitAll (blocking the code until all the tasks are completed) for you, so you don't have to do that either. If you want to have the tasks run in the background without caring when they complete, then you want Task.Factory.StartNew().

提交回复
热议问题