0

The existing question suggests CurrentClockSpeed, but in my system, it just returns the same value as MaxClockSpeed. The code below prints out the same two values over and over again.

        Task.Run(() =>
        {
            ManagementObject Mo = new ManagementObject("Win32_Processor.DeviceID='CPU0'");
            while (true)
            {
                Debug.WriteLine("Max=" + Mo["MaxClockSpeed"] + ", Current=" + Mo["CurrentClockSpeed"]);
                System.Threading.Thread.Sleep(1000);
            }
            Mo.Dispose(); //return and such later in the code
        });

But all other applications like Task Manager, CPU-Z, Hardware Info, etc, show variable clock speed. That is, if I run a process that uses 100% of the CPU, the speed goes up, and if I terminate that process, it goes down. How can I get THAT value?

I mean, for example, the value in the "Speed" section of the screenshot I found in Google Search. Not the "Maximum speed" value that never changes.

enter image description here

Damn Vegetables
  • 11,484
  • 13
  • 80
  • 135
  • Have you seen [this](https://stackoverflow.com/a/57873417/1911064) related post? – Axel Kemper Jun 08 '20 at 16:50
  • @AxelKemper Maybe that is it. It seems to be that `cpuCounter.NextValue()` is returning the percentage of the base clock speed. When I tested it it was changing from about 100 to about 110. – Damn Vegetables Jun 08 '20 at 20:13

1 Answers1

0

If you mean CPU current usage processes use this function in seperate thread :

private void get_cpuUsage()
        {
            try
            {
                string processname = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
                var perfCounter = new PerformanceCounter("Process", "% Processor Time", processname);

                int coreCount = 0;
                foreach (var item in new System.Management.ManagementObjectSearcher("Select * from Win32_Processor").Get())
                {
                    coreCount += int.Parse(item["NumberOfCores"].ToString());
                }

                while (true)
                {
                    Thread.Sleep(500);
                    double perfVal = perfCounter.NextValue() / Environment.ProcessorCount;
                    int cpu = (int)Math.Round(perfVal, 0);// / 
                    double cpuvalue = Math.Round(perfVal, 1);
                    Invoke((MethodInvoker)delegate
                    {

                        cpu_bar.Text = cpuvalue.ToString(); // diaplay current % processes 
                    });
                }
            }
            catch(Exception ex)
            {
messagebox.show(ex.message);

            }
        }
Isaac Be
  • 81
  • 1
  • 10
  • No, not the CPU utilisation, the CPU clock speed. I am not sure why you though so, but if that was because the red arrow on the CPU usage graph, I found this image from Google Image Search, as I had noted, so it was not I who put that red arrow and I am not interested in CPU usage. – Damn Vegetables Jun 08 '20 at 20:05