How I can get number of logical cores in CPU?
I need this to determine how many threads I should run in my application.
How I can get number of logical cores in CPU?
I need this to determine how many threads I should run in my application.
You can get number of logical processors through the Environment class
number of cores:
int coreCount = 0;
foreach (var item in new System.Management.ManagementObjectSearcher("Select * from Win32_Processor").Get())
{
coreCount += int.Parse(item["NumberOfCores"].ToString());
}
Console.WriteLine("Number Of Cores: {0}", coreCount);
number of logical processors
foreach (var item in new System.Management.ManagementObjectSearcher("Select * from Win32_ComputerSystem").Get())
{
Console.WriteLine("Number Of Logical Processors: {0}", item["NumberOfLogicalProcessors"]);
}
Environment.ProcessorCount
using System;
class Sample
{
public static void Main()
{
Console.WriteLine("The number of processors on this computer is {0}.",
Environment.ProcessorCount);
}
}
go through this link http://msdn.microsoft.com/en-us/library/system.environment.processorcount.aspx
Use the Environment.ProcessorCount property, it returns the number of logical cores.
You can get number of logical processors through the Environment class
number of cores:
int coreCount = 0;
foreach (var item in new System.Management.ManagementObjectSearcher("Select * from Win32_Processor").Get())
{
coreCount += int.Parse(item["NumberOfCores"].ToString());
}
Console.WriteLine("Number Of Cores: {0}", coreCount);
number of logical processors
foreach (var item in new System.Management.ManagementObjectSearcher("Select * from Win32_ComputerSystem").Get())
{
Console.WriteLine("Number Of Logical Processors: {0}", item["NumberOfLogicalProcessors"]);
}
Environment.ProcessorCount
using System;
class Sample
{
public static void Main()
{
Console.WriteLine("The number of processors on this computer is {0}.",
Environment.ProcessorCount);
}
}
go through this link http://msdn.microsoft.com/en-us/library/system.environment.processorcount.aspx
© 2022 - 2024 — McMap. All rights reserved.