I have created a window application in C#.Now I want to set the CPU affinity for this application.I may have 2 processors,4 processors,8 processors or may be more than 8 process
The provided sample program by Alex Filipovivi seems incorrect, in that it ORs processor numbers into newAffinity without first converting them into a set bit. So if you input 3,4 to this program, you get an affinity mask of 7, which is cores 1, 2, and 3! The mask should be set to 12 (hex 0xC, binary 1100, which has bits 2 and 3 set, if bit 0 is the least significant bit).
Replacing
newAffinity = NewAffinity | int.Parse(item);
with
newAffinity = newAffinity | (1 << int.Parse(item)-1);
Is one reasonable way to do that.