VB.net流程亲和力 [英] VB.net Process Affinity
问题描述
目标:我的目标是将所有正在运行的进程的关联性设置为1个核心。然后启动一个具有所有核心相似性的程序。
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
推荐答案
有C#解决方案此处。
总而言之,您需要遍历所有进程( Process.GetProcesses
),并将其 .ProcessorAffinity
设置为 New IntPtr(1)
,然后开始新的过程。 (默认情况下已经使用所有核心,但是为了完整起见,如果您希望新进程具有不同的相似性,请以与上述相同的方式在启动后进行设置。)
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.)
所有代码:
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)
这篇关于VB.net流程亲和力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!