トップ回答者
マネージドコードでCPUのコア数を知りたい

質問
回答
-
インテルCore2 Duo のPCが近くにないので確認できないんですが,
WMI でも良いのなら,参照に System.Management を追加して,//uint numberOfLogicalProcessors = 0u; // not supported
uint numberOfProcessors = 0u;
System.Management.ManagementClass mc = new System.Management.ManagementClass("Win32_ComputerSystem");
foreach (System.Management.ManagementObject mo in mc.GetInstances())
{
// Vistaでなく,WinXPなどでは,NumberOfProcessors のみのサポートのため,
// 値が2 となっても,CPUでなのか,CPUでcore 2なのかは不明となる。
numberOfProcessors = Convert.ToUInt32(mo.GetPropertyValue("NumberOfProcessors"));
Console.WriteLine("NumberOfProcessors {0} ", numberOfProcessors);
}
で,微妙にわかるようです。Vistaだときっとちゃんとわかるんだと思います。というのは,
Windows Server 2003, Windows XP, and Windows 2000: Because the NumberOfLogicalProcessors property is not available, NumberOfProcessors indicates the number of logical processors available in the system. In the case of a computer system that has two physical processors each containing two logical processors, the value of NumberOfProcessors is 4.
Windows Server 2003, Windows XP, and Windows 2000 では,
NumberOfLogicalProcessors プロパティが得られないので,(その代わりに)
NumberOfPorcessors が,システム上の logical processors の数を指す。とあります。でも,インテルCore2 Duoの環境がないので確認できてません。 <--- 注意
すべての返信
-
インテルCore2 Duo のPCが近くにないので確認できないんですが,
WMI でも良いのなら,参照に System.Management を追加して,//uint numberOfLogicalProcessors = 0u; // not supported
uint numberOfProcessors = 0u;
System.Management.ManagementClass mc = new System.Management.ManagementClass("Win32_ComputerSystem");
foreach (System.Management.ManagementObject mo in mc.GetInstances())
{
// Vistaでなく,WinXPなどでは,NumberOfProcessors のみのサポートのため,
// 値が2 となっても,CPUでなのか,CPUでcore 2なのかは不明となる。
numberOfProcessors = Convert.ToUInt32(mo.GetPropertyValue("NumberOfProcessors"));
Console.WriteLine("NumberOfProcessors {0} ", numberOfProcessors);
}
で,微妙にわかるようです。Vistaだときっとちゃんとわかるんだと思います。というのは,
Windows Server 2003, Windows XP, and Windows 2000: Because the NumberOfLogicalProcessors property is not available, NumberOfProcessors indicates the number of logical processors available in the system. In the case of a computer system that has two physical processors each containing two logical processors, the value of NumberOfProcessors is 4.
Windows Server 2003, Windows XP, and Windows 2000 では,
NumberOfLogicalProcessors プロパティが得られないので,(その代わりに)
NumberOfPorcessors が,システム上の logical processors の数を指す。とあります。でも,インテルCore2 Duoの環境がないので確認できてません。 <--- 注意