You can get the system CPU frequency by using the ManagementObjectSearcher
class from the System.Management
namespace. Here's an example code:
main.cs496 chars18 lines
This program creates a ManagementObjectSearcher
object to search for CPU-related information on the system. The query
parameter passed to the constructor of ManagementObjectSearcher
specifies to select all the properties of the Win32_Processor
class.
Then, the program loops through the resulting collection of ManagementObject
objects and gets the value of the MaxClockSpeed
property, which represents the maximum clock speed of the CPU. This value is cast to an unsigned integer and printed to the console.
Note that this code snippet only retrieves the maximum clock speed of the CPU. If you want to get additional information about the CPU, such as the number of cores or the manufacturer, you can modify the query
parameter passed to ManagementObjectSearcher
according to the properties of the Win32_Processor
class.
gistlibby LogSnag