|The complete source code as well as compiled, ready for tests version of this example is available here (zip, 165k, Delphi version).|
I have been asked many times about this example. One guy have even promised to pay me for this example (but he has not ;) ). I considered this example to be too simple for the demos section of my site but finally I decided to form it and place here.
Well, let's do it.
Create new project and place the following components onto it's surface:
The resulting form should look like this one:
Now the PerfMonitor component should be configured. The first necessary operation is setting the LocaleId property. This property defines the language of performance object's and counter's titles. Set this property to 009. It means English, and this value is valid for localized versions of Windows NT/2000 too:
Now adjust the Items property of this component. This property contains a collection of monitoring items. Add one item to it and set it's properties.
At first set the ObjectName to "Processor". The drop-down list contains the names of all performance objects existing on your system and you could choose the object name from this list.
Now you can set the value of CounterName property. This property has drop-down list of possible items too. It contains the names of all counters that are defined for the performance object specified by ObjectName property.
Well, the monitoring item is configured properly now. Add the following code to the Timer.OnTimer event handler:
Only one comment is necessary here. The "Processor" performance object is multi-instance because there could be more then one processor in the system. So the indexed property InstanceValues must be used to obtain the counter value. In our case it will be the CPU usage value.
And one more thing. The _Busy boolean variable is used to prevent re-entering the refreshing loop. Add the declaration of this variable to the private section of form's declaration.
Now our example is ready for tests. Save it, compile it, run it and enjoy!
|Add your comment | Read comments|