Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Management;
- using System.Timers;
- namespace ezCPU
- {
- public partial class ezCPU : Form
- {
- public ezCPU()
- {
- InitializeComponent();
- }
- //On load, do this
- private void Form1_Load(object sender, EventArgs e)
- {
- this.Text = this.Text + " - v" + Application.ProductVersion;
- getCPUInfo();
- }
- //Convert the string format to a readable double
- public string convertClockSpeed(string s)
- {
- double clockSpeed = Convert.ToDouble(s);
- double newClockSpeed = (clockSpeed / 1000);
- return Math.Round(newClockSpeed, 2).ToString() + " GHz";
- }
- public void getCPUInfo()
- {
- //Create the ManagementObjectSearcher grabbing everything from the Win32_Processor
- ManagementObjectSearcher myProcessorObject = new ManagementObjectSearcher("select * from Win32_Processor");
- //Loop through the returned results
- foreach (ManagementObject obj in myProcessorObject.Get())
- {
- //Assign CPU Name
- string cpuName = obj["Name"].ToString();
- txtCPUName.Text = cpuName;
- //Assign CPU Manufacturer
- string cpuManufacturer = obj["Manufacturer"].ToString();
- if (cpuManufacturer == "GenuineIntel")
- {
- txtCPUManufacturer.Text = "Genuine Intel";
- }
- else
- {
- txtCPUManufacturer.Text = cpuManufacturer;
- }
- //Assign CPU cores
- string cpuCores = obj["NumberOfCores"].ToString();
- txtCores.Text = cpuCores;
- //Assign CPU threads
- string cpuThreads = obj["ThreadCount"].ToString();
- txtThreads.Text = cpuThreads;
- //Assign CPU max speed
- string cpuMaxSpeed = obj["MaxClockSpeed"].ToString();
- txtClockSpeed.Text = convertClockSpeed(cpuMaxSpeed);
- updateCPUSpeed();
- }
- }
- private async Task updateCPUSpeed()
- {
- while (true)
- {
- //Each tick, create a new searcher
- ManagementObjectSearcher myProcessorObject = new ManagementObjectSearcher("select * from Win32_Processor");
- //For each searcher, assign the current CPU clock speed
- foreach (ManagementObject obj in myProcessorObject.Get())
- {
- //Display it
- string currentClockSpeed = obj["CurrentClockSpeed"].ToString();
- txtCPUSpeed.Text = convertClockSpeed(currentClockSpeed);
- }
- await Task.Delay(10);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement