Hi,
I have a feeling the answer to this is no, but using .Net 4.0's Parallelism, can you set the amount of cores on which to run i.e. if your running a Quad Core, can you set your Application to only use 2 of them?
Thanks
Hi,
I have a feeling the answer to this is no, but using .Net 4.0's Parallelism, can you set the amount of cores on which to run i.e. if your running a Quad Core, can you set your Application to only use 2 of them?
Thanks
Yes, it is a built-in capability of Parallel.For(). Use one of the overloads that accepts a ParallelOptions object, set its MaxDegreeOfParallelism property. For example:
using System;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
var options = new ParallelOptions();
options.MaxDegreeOfParallelism = 2;
Parallel.For(0, 100, options, (ix) => {
//..
});
}
}