[英]How can more Tasks share a common List in C# with TPL?
How can more Tasks share a common List in C# with TPL? 如何使用TPL在C#中共享更多任务?
I have a List and I need to divide the workload on more Tasks. 我有一个列表,我需要将工作量分配给更多任务。 Each Task needs to take one element from the List and do something with it.
每个任务都需要从列表中选择一个元素并对其进行处理。 The first question is whether I decide how many Tasks to create, or I let the library decide that?
第一个问题是我决定要创建多少个任务,还是由库来决定?
But if I let the library decide that, then how does the List splitting happen? 但是,如果我让库决定,那么列表拆分是如何发生的?
Thanks 谢谢
if I understand properly, you can use the Parallel.ForEach() . 如果我理解正确,则可以使用Parallel.ForEach() 。 See an example here .
在这里查看示例 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.