Does Parallel.ForEach Block?

后端 未结 2 1564
长情又很酷
长情又很酷 2020-12-13 23:16

Does the .net function Parallel.ForEach block the calling thread? My guess as to the behavior is one of these:

  1. Yes, it blocks until the slowest item executing
2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-13 23:57

    Number 1 is correct; Parallel.ForEach does not return until the loop has completed. If you don't want that behavior, you can simply execute your loop as a Task and run it on another thread.

提交回复
热议问题