C# 设置使用单个cpu

2026-02-12 12:29:09

1、1.首先,实现方法进程与指定cpu绑定:SetProcessAffinityMask(GetCurrentProcess(),dwMask);

C# 设置使用单个cpu

2、2.线程与指定cpu绑定:SetThreadAffinityMask(GetCurrentThread(),dwMask);dwMask为CPU序号的或运算值:1(0001)

C# 设置使用单个cpu

3、3.代表只运行在CPU1,2(0010)代表只运行在CPU2,3(0011)代表可以运行在CPU1和CPU2,以此类推。

C# 设置使用单个cpu

4、4.设置之前最好判断一下系统有几个CPU:SYSTEM_INFOSystemInfo;GetSystemInfo(&SystemInfo);CPU个数:SystemInfo.dwNumberOfProcessors

C# 设置使用单个cpu

5、5.当前启用的CPU序号:SystemInfo.dwActiveProcessorMask,Mask representing the set of processors configured into the system. Bit 0 is processor 0;bit 31 is processor 31.

C# 设置使用单个cpu

猜你喜欢