Can Task MaxDegreeOfParallelism can take every time the first n object from my list?

后端 未结 3 1170
执笔经年
执笔经年 2021-01-14 03:31

I am opening n concurrent threads in my function:

List _files = new List();

public void Start()
{
    Cancellation         


        
3条回答
  •  广开言路
    2021-01-14 03:35

    Of course the files are randomly selected, that's the whole point of parallel.foreach. If you go parallel, the 5 threads you specified will use the input as it's decided by the data partionier.

    But if you really want to maintain the order, check the OrderablePartitioner you can specify for the parallel.foreach. -> http://msdn.microsoft.com/en-us/library/dd989583.aspx But of course this will decrease performance, but it allows you to specify how the partitions are created for the threads.

提交回复
热议问题