Skip to content

Instantly share code, notes, and snippets.

@luisdeol
Created May 26, 2020 12:57
Show Gist options
  • Save luisdeol/8c228ce5126feee44ba47e428e0b4416 to your computer and use it in GitHub Desktop.
Save luisdeol/8c228ce5126feee44ba47e428e0b4416 to your computer and use it in GitHub Desktop.
3.5: Creating and reading Performance Counters.
using System;
using System.Diagnostics;
namespace _35_ApplicationDiagnostics
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Press ENTER to stop.");
using (var performanceCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total"))
{
var text = "Processor Time: ";
Console.WriteLine("Processor Time: ");
do
{
while(!Console.KeyAvailable)
{
Console.WriteLine(performanceCounter.NextValue());
Console.SetCursorPosition(text.Length, Console.CursorTop);
}
} while (Console.ReadKey(true).Key != ConsoleKey.Enter);
}
Console.Read();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment