I am looking for execute an external program inside a .net application.
I need to assign a concrete processor to that program. I need to execute the program several times and every time on a different processor. I need to wait for external program termination.
To simplify I have done a small spike (console) app to work on it:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ExecuteExternalInParallelWithAffinity
{
class Program
{
static void Main(string[] args)
{
for (int i = 1; i < 3; i++)
{
var processnumber = i;
Task.Factory.StartNew(() =>
{
Process p = Process.Start("notepad.exe");
p.ProcessorAffinity = (IntPtr)processnumber;
}).ContinueWith(t =>
{
Console.Out.WriteLine(string.Format("Process ended on processor: {0}", processnumber));
});
}
Console.ReadKey();
}
}
}
My questions:
1.- Can I assign processor affinity before executing the process.
2.- In spite I am checkin Notepad
on task manager, all of them are assigned to processor 0.