
In C# (.NET 6 and above), there is now a very simple way to read out the CPU load with minimal overhead - i.e. without threads. The PerformanceCounter from the System.Diagnostics namespace helps us with this.
1static async Task Main(string[] args)
2{
3 CancellationToken token = new(); // optional external cancel
4
5 PerformanceCounter cpuCounter = new("Processor", "% Processor Time", "_Total");
6 using PeriodicTimer timer = new(TimeSpan.FromSeconds(1));
7
8 while (await timer.WaitForNextTickAsync(token) && !token.IsCancellationRequested)
9 {
10 Console.WriteLine(cpuCounter.NextValue());
11 }
12}
Hint: the first query of the CPU values always returns 0.0. This is also specified accordingly in the documentation: If the calculated value of a counter depends on two counter reads, the first read operation returns 0.0.
Related articles

Dec 05, 2025 · 5 min read
IMemoryCache Entry Invalidation (Manual Cache Busting)
IMemoryCache is great for speeding up expensive operations (database reads, HTTP calls, heavy computations). But many real systems need more …

Nov 08, 2025 · 8 min read
.NET 10 Release: What's New (LTS) and What to Upgrade First
.NET 10 is the next Long-Term Support (LTS) release in the .NET family. LTS matters because it’s the version many teams standardize on …

Sep 24, 2025 · 9 min read
Automatically discover tools for Azure OpenAI Realtime API
Azure now provides a unified Realtime API for low‑latency, multimodal conversations over WebRTC or WebSockets. If you’ve used the earlier …
Let's Work Together
Looking for an experienced Platform Architect or Engineer for your next project? Whether it's cloud migration, platform modernization or building new solutions from scratch - I'm here to help you succeed.

Comments