-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCpuPerformance.cs
35 lines (30 loc) · 1.04 KB
/
CpuPerformance.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using Microsoft.WindowsAPICodePack.Taskbar;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TaskbarPerformance
{
public class CpuPerformance : AbstractPerformanceWindow
{
private readonly PerformanceCounter perCounter = new()
{
CategoryName = "Processor",
CounterName = "% Processor time",
InstanceName = "_Total"
};
public CpuPerformance(Timer timer) :base(timer) {}
public override string FormatText(float value) => $"CPU: {Math.Floor(value)} %";
public override TaskbarProgressBarState MapState(float value) => value switch
{
100 => TaskbarProgressBarState.Error,
> 75 => TaskbarProgressBarState.Paused,
_ => TaskbarProgressBarState.Normal,
};
public override float ProvideMaxValue() => 100;
public override float ProvideValue() => perCounter.NextValue();
}
}