简体   繁体   中英

VB.net Process Affinity

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM