Performance counters
Windows gives us lots of tools to monitor our systems, such as EventViewer. We can use those tools in our own systems as well. For instance, there are a lot of performance counters available that you can access both inside and outside of your code.
Let’s look at how to get that in our code first.
I started a new Console application, added the System.Diagnostic NuGet package, and then wrote the following code:
using System.Diagnostics;
using ExtensionLibrary;
#pragma warning disable CA1416
var counter = 0;
var cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
while (true)
{
if (counter++ == 10)
// Start a method on a background thread
Task.Run(() =>
{
...