K
Kevin Jackson
Hello,
How does one go about determining the number of processors a server has in
..NET???
Thanks
How does one go about determining the number of processors a server has in
..NET???
Thanks
Milosz Skalecki said:You can also use WINAPI
add
using System.Runtime.InteropServices;
in using section
-- BEGIN CODE --
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEM_INFO
{
public uint dwOemId;
public uint dwPageSize;
public uint lpMinimumApplicationAddress;
public uint lpMaximumApplicationAddress;
public uint dwActiveProcessorMask;
public uint dwNumberOfProcessors;
public uint dwProcessorType;
public uint dwAllocationGranularity;
public uint dwProcessorLevel;
public uint dwProcessorRevision;
}
[DllImport("kernel32")]
static extern void GetSystemInfo(ref SYSTEM_INFO pSI);
private uint GetNuberOfProcessors()
{
SYSTEM_INFO info = new SYSTEM_INFO();
GetSystemInfo(ref info);
return info.dwNumberOfProcessors;
}
-- END CODE --
hope this helps
--
Milosz Skalecki
MCP, MCAD
Kevin Jackson said:Hello,
How does one go about determining the number of processors a server has
in
..NET???
Thanks
Milosz Skalecki said:You can also use WINAPI
add
using System.Runtime.InteropServices;
in using section
-- BEGIN CODE --
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEM_INFO
{
public uint dwOemId;
public uint dwPageSize;
public uint lpMinimumApplicationAddress;
public uint lpMaximumApplicationAddress;
public uint dwActiveProcessorMask;
public uint dwNumberOfProcessors;
public uint dwProcessorType;
public uint dwAllocationGranularity;
public uint dwProcessorLevel;
public uint dwProcessorRevision;
}
[DllImport("kernel32")]
static extern void GetSystemInfo(ref SYSTEM_INFO pSI);
private uint GetNuberOfProcessors()
{
SYSTEM_INFO info = new SYSTEM_INFO();
GetSystemInfo(ref info);
return info.dwNumberOfProcessors;
}
-- END CODE --
hope this helps
--
Milosz Skalecki
MCP, MCAD
Kevin Jackson said:Hello,
How does one go about determining the number of processors a server has
in
..NET???
Thanks
Not just hyperthreaded CPUs (or virtual processors; and obviously twoKevin said:Well, this count includes hyperthreaded procs.
Anyone know of code that can distinguish between real and hyperthreaded
procs?
Thanks
Milosz Skalecki said:You can also use WINAPI
add
using System.Runtime.InteropServices;
in using section
-- BEGIN CODE --
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEM_INFO
{
public uint dwOemId;
public uint dwPageSize;
public uint lpMinimumApplicationAddress;
public uint lpMaximumApplicationAddress;
public uint dwActiveProcessorMask;
public uint dwNumberOfProcessors;
public uint dwProcessorType;
public uint dwAllocationGranularity;
public uint dwProcessorLevel;
public uint dwProcessorRevision;
}
[DllImport("kernel32")]
static extern void GetSystemInfo(ref SYSTEM_INFO pSI);
private uint GetNuberOfProcessors()
{
SYSTEM_INFO info = new SYSTEM_INFO();
GetSystemInfo(ref info);
return info.dwNumberOfProcessors;
}
-- END CODE --
hope this helps
--
Milosz Skalecki
MCP, MCAD
Kevin Jackson said:Hello,
How does one go about determining the number of processors a server has
in
..NET???
Thanks
john smith said:Not just hyperthreaded CPUs (or virtual processors; and obviously twoKevin said:Well, this count includes hyperthreaded procs.
Anyone know of code that can distinguish between real and hyperthreaded
procs?
Thanks
Milosz Skalecki said:You can also use WINAPI
add
using System.Runtime.InteropServices;
in using section
-- BEGIN CODE --
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEM_INFO
{
public uint dwOemId;
public uint dwPageSize;
public uint lpMinimumApplicationAddress;
public uint lpMaximumApplicationAddress;
public uint dwActiveProcessorMask;
public uint dwNumberOfProcessors;
public uint dwProcessorType;
public uint dwAllocationGranularity;
public uint dwProcessorLevel;
public uint dwProcessorRevision;
}
[DllImport("kernel32")]
static extern void GetSystemInfo(ref SYSTEM_INFO pSI);
private uint GetNuberOfProcessors()
{
SYSTEM_INFO info = new SYSTEM_INFO();
GetSystemInfo(ref info);
return info.dwNumberOfProcessors;
}
-- END CODE --
hope this helps
--
Milosz Skalecki
MCP, MCAD
:
Hello,
How does one go about determining the number of processors a server has
in
..NET???
Thanks
physical CPUs too) but also dual core CPUs. Same story if you'd use WMI to
get the data. The only ways I know isn't exactly quick or simple (low
level stuff - rolling your own fancy class using various CPUID calls and
checks depending on VendorID/model; but there are also functions like
GetLogicalProcessorInformation). There's only so many ways to get the
information... I wish WMI's support improves in this area but I doubt
we'll see that unfortunately.