每个循环的最大并行线程数



如何为此循环添加最大并行线程数:

Parallel.ForEach(DataRow drValue in dtValues.Rows)
{
}

这是行不通的:

Parallel.ForEach(DataRow drValue in dtValues.Rows, new ParallelOptions {MaxDegreeOfParallelism = 4})
{
}

尝试使用 lambda:

Parallel.ForEach(dtValues.Rows.AsEnumerable(), new ParallelOptions { MaxDegreeOfParallelism = 4 }, drValue =>
{
    //logic goes here
});

要使用此方法,您必须在项目中包含System.Data.DataSetExtensions.dll。看这里。

最新更新