public static void SetProcessAffinityMask(int affinity, string processName = null)
{
Process myProcess = GetProcessByName(ref processName);
Console.WriteLine("Process {0} Old Affinity Mask is : {1}", processName, FormatAffinity((int)myProcess.ProcessorAffinity));
myProcess.ProcessorAffinity = new IntPtr(affinity);
Console.WriteLine("Process {0} New Affinity Mask is : {1}", processName, FormatAffinity((int)myProcess.ProcessorAffinity));
}
Example of usage :
private static void Main(string[] args)
{
int newAffinity = Convert.ToInt32("10101010", 2);
SetProcessAffinityMask(newAffinity);
Console.ReadKey();
}
// Output :
// Process Test.vshost Old Affinity Mask is : 11111111
// Process Test.vshost New Affinity Mask is : 10101010