Class CpuUsage
Gets CPU usage.
public sealed class CpuUsage : IDisposable
Remarks
You can use the static functions (easier) or a CpuUsage instance. A CpuUsage instance must be disposed (use using
).
Examples
using var u = new CpuUsage(); //all processes
//using var u = new CpuUsage(process.getProcessId("Au.Editor.exe")); //single process
//using var u = new CpuUsage(process.getProcessIds("chrome.exe")); //all Chrome processes
for (; ; ) {
if (!u.Start()) break;
Thread.Sleep(500);
print.it(u.Stop());
}
Namespace: Au.More
Assembly: Au.dll
Constructors
Name | Description |
---|---|
CpuUsage() | Use this constructor to get CPU usage of all processes (sum). |
CpuUsage(IEnumerable<int>) | Use this constructor to get CPU usage of multiple processes (sum). |
CpuUsage(int) | Use this constructor to get CPU usage of a process. |
Properties
Name | Description |
---|---|
ProcessorCount | Get the number of logical CPU in the system. |
Methods
Name | Description |
---|---|
Dispose() | |
OfAllProcesses(int) | Gets CPU usage of all processes (sum). |
OfProcess(int, int) | Gets CPU usage of a process. |
OfProcesses(IEnumerable<int>, int) | Gets CPU usage of multiple processes (sum). |
Start() | Starts measuring CPU usage. |
Stop() | Ends measuring CPU usage, and gets result.
Call this after calling CpuUsage.Start and waiting at least 1 ms. Don't call if Start returned |