2012-11-05 29 views
2

目标:我的目标是将所有正在运行的进程的关联设置为1个核心。然后用所有核心的亲和力启动一个程序。VB.net Process Affinity

技能等级:我在编程方面的技能水平一般都是初学者。这是我的第一语言。

需要:我希望得到一些关于这个编码的帮助,也许还有一些文章或代码的描述。谢谢

回答

1

有一个C#解决方案here

总之,您需要遍历所有进程(Process.GetProcesses)并将它们的.ProcessorAffinity设置为New IntPtr(1),然后开始新的进程。 (默认情况下已使用所有核心,但对于完整性,如果你想在新的进程有不同的亲和力,设置它已经开始与上述相同的方式后。)

所有代码:

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)