從我所知道的,Environment.ProcessorCount
可能會返回一個不正確的值在WOW64下運行時(作爲一個64位操作系統上的32位進程)因爲它依賴的P/Invoke簽名使用GetSystemInfo
而不是GetNativeSystemInfo
。這似乎是一個明顯的問題,所以我不知道爲什麼就不會被這點解決。
試試這個,看看它是否解決了問題:
private static class NativeMethods
{
[StructLayout(LayoutKind.Sequential)]
internal struct SYSTEM_INFO
{
public ushort wProcessorArchitecture;
public ushort wReserved;
public uint dwPageSize;
public IntPtr lpMinimumApplicationAddress;
public IntPtr lpMaximumApplicationAddress;
public UIntPtr dwActiveProcessorMask;
public uint dwNumberOfProcessors;
public uint dwProcessorType;
public uint dwAllocationGranularity;
public ushort wProcessorLevel;
public ushort wProcessorRevision;
}
[DllImport("kernel32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
internal static extern void GetNativeSystemInfo(ref SYSTEM_INFO lpSystemInfo);
}
public static int ProcessorCount
{
get
{
NativeMethods.SYSTEM_INFO lpSystemInfo = new NativeMethods.SYSTEM_INFO();
NativeMethods.GetNativeSystemInfo(ref lpSystemInfo);
return (int)lpSystemInfo.dwNumberOfProcessors;
}
}
您的鏈接不工作atm ... – ChristopheD 2010-04-04 18:46:38
您在Taskmgr.exe,Performance選項卡中看到了多少個處理器? – 2010-04-04 19:00:37
該鏈接有一天工作。 – 2010-04-04 19:06:04