
Access Performance Counters #73
Chapter 9, Server Explorer Hacks
|
301
HACK
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "PerfCounterExample";
this.Text = "PerfCounterExample";
this.Load +=
new System.EventHandler(this.PerfCounterExample_Load);
((System.ComponentModel.ISupportInitialize)
(this.performanceCounter1)).EndInit( );
this.ResumeLayout(false);
}
#endregion
private void PerfCounterExample_Load(
object sender,
System.EventArgs e)
{
//Get the value of the performance counter
label2.Text = performanceCounter1.NextValue( ).ToString( );
}
}
}
When you run this code, it will produce the form shown in Figure 9-4.
Counter Information
You can view additional information about counters by right-clicking on a
category and clicking the View Category menu item. This will display the
Performance Counter Builder form (Figure 9-5), which includes a descrip-
tion of the category as well as a list of all the performance counters in that
category. Click on a performance counter and you will be shown a descrip-
tion of it. This is a great way to investigate the counters in each category and
what they report on.
The Server Explorer makes it easy to browse all the performance counters on
your machine and then access them in your application.
Figure 9-4. PerfCounter Example form