是否有可能定义的Parallel.For执行顺序? [英] Is it possible to define the execution order in Parallel.For?
本文介绍了是否有可能定义的Parallel.For执行顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
// parameters.Count == 10
// actualFreeLicenses == 2
Parallel.For(0, parameters.Count, new ParallelOptions()
{
MaxDegreeOfParallelism = actualFreeLicenses
}, i =>
{
ExternalProgram(i);
}
);
当我执行上述code我注意到的价值我
传递给 ExternalProgram
方法是1和; 6,后2及7,后3及8 ...
When I execute the above code I notice that the value of i
passed to the ExternalProgram
method are 1 & 6, later 2 & 7, later 3 & 8 ...
如果我有14个参数和2个许可证,它总是推出1安培; 8,以后2及9 ...
If I have 14 Parameters and 2 licenses it always launch 1 & 8, later 2 & 9 ...
是否有可能定义顺序:先1安培; 2,后3及4等?
Is it possible to define order: first 1 & 2, later 3 & 4 etc?
推荐答案
如果您使用的是并行的,他们的执行顺序为关联,因此平行的不是。您应该使用顺序工作流如果订单与您有关。
If you are using Parallel the order in which they are executed is not of relevance therefore "Parallel". You should use a sequential workflow if the order is relevant for you.
这篇关于是否有可能定义的Parallel.For执行顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文