How can I wait till the Parallel.ForEach completes

前端 未结 3 1638
轮回少年
轮回少年 2020-12-15 02:16

I\'m using TPL in my current project and using Parallel.Foreach to spin many threads. The Task class contains Wait() to wait till the task gets completed. Like that, how I c

3条回答
  •  不思量自难忘°
    2020-12-15 02:41

    As everyone here said - you dont need to wait for it. What I can add from my experience: If you have an async body to execute and you await some async calls inside, it just ran through my code and did not wait for anything. So I just replaced the await with .Result - then it worked as intended. I couldnt find out though why is that so :/

提交回复
热议问题