问题
Goal: My goal is to set all running processes's affinity to 1 core. Then launch a program with the affinity of all the cores.
Skill Lvl: My skill level in programming in general is pretty much beginner. This is my first language.
Need: I would like some help with this coding and maybe an article or description of the code. Thank you
回答1:
There is a C# solution here.
In summary, you need to loop through all processes (Process.GetProcesses
) and set their .ProcessorAffinity
to New IntPtr(1)
, then start your new process. (The default is already to use all cores, but for completeness, if you want the new process to have a different affinity, set it after it's been started the same way as above.)
All the code:
Dim procs = Process.GetProcesses
For Each p In procs
p.ProcessorAffinity = New IntPtr(1)
Next
Dim myProc = Process.Start("notepad.exe")
' Stop here to answer the OP.
' This sets the new Notepad process to be the only process running on the second CPU:
myProc.ProcessorAffinity = New IntPtr(2)
来源:https://stackoverflow.com/questions/13240679/vb-net-process-affinity