Created
May 26, 2020 12:57
-
-
Save luisdeol/8c228ce5126feee44ba47e428e0b4416 to your computer and use it in GitHub Desktop.
3.5: Creating and reading Performance Counters.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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