Pass an instance of ParallelOptions
with ParallelOptions.MaxDegreeOfParallelism
set to 4 to Parallel.ForEach
.
Nevertheless this might not make sense on other machines, that might have more or less cores than you. In general you should let the framework decide the degree of parallelism.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…