Counters in C#


Counters in C# are performance counters that lets you know about your applications performance.

When you will build an application, whether it is a web app, mobile app or even desktop app, you would definitely need to monitor the performance.

For performance counters in C#, use the System.Diagnostics.PerformanceCounter class. Set the instance of the PerformanceCounter class and work with the following properties: CategoryName, CounterName, MachineName and ReadOnly.

To get the performance categories.

var counter = PerformanceCounterCategory.GetCategories();

Now SET performance counters for the category processor.

var counter = PerformanceCounterCategory.GetCategories()
   .FirstOrDefault(category => category.CategoryName == "Processor");

Updated on: 30-Jul-2019

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements