c# - WMI LoadPercentage call is very slow -


I'm trying to use WMI to check my CPU load (XOn, 4 core). I'm running XP 64 (SP2).

  Private Zero Button 1_Click (Object Sender, EventArgs E) {Language & lt; String, string & gt; CpuInfo = New Dictionary & lt; String, string & gt; (); Management object explorer explorer = new management object search ("Select * from Win32_Processor"); Foreign currency (keyword keyword keyword search.) {CpuInfo.Add ("LoadPercentage" + queryObj ["DeviceID"]. ToString (), queryObs ["LoadPerfect"]. ToString ()); } Foreach (keyValuePair & lt; string; string; gt; kvp in cpuInfo) {richTextBox1.AppendText (String.Format ("{0} {1} \ n", kvp.Key, kvp.Value)); }}   

The example runs up, but it is very slow, approximately 5 seconds. Is this a WMI issue or am I doing something wrong?

OK, I provide this as an answer, though it can not be - Yet I think this is not suitable for a comment.

I have the same problem on Windows XP SP3 and Windows 7. As soon as I run the LoadPercentage property in the WMI query, approximately 1 second per physical processor (such as Win32_Processor ). The opposite also is true: if I include all the properties in the query, but does not include the LoadPercentage property, then it runs in a few milliseconds.

This behavior can happen (i.e. wmic cpu ) with many tools provided, custom or OS is celebrated.

I can only guess what is the reason for it, it is LoadPercentage (emphasis):

The load capacity of each processor, The average processor loading for last second shows the total computing burden for each processor at a time. This property is inherited from CIM_Processor.

The implementation of the WMI provider can actually require 1 second when you sample the load percentages "Average to the previous one" while placing calls. I would know that the provider does in some way in the background and only gives a call at the time of the call. But somehow, this is just speculation.

Update : FWIW, Windows 8 developer preview looks the same behavior.

Comments