VB.net Process Affinity

試著忘記壹切 提交于 2019-12-24 02:51:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!