I need to get the memory and CPU usage of an application in C #, with the code below (using PerformanceCounter
) did not get the same value as the Task Manager of Windows .
PerformanceCounter cpu;
PerformanceCounter ram;
cpu = new PerformanceCounter("Process", "% Processor Time", "Servidor - estoque", true);
ram = new PerformanceCounter("Process", "Private Bytes", "Servidor - estoque", true);
int Cpu = Convert.ToInt32(cpu.NextValue());
int Ram = Convert.ToInt32(ram.NextValue());
CPU.Value = Cpu;
RAM.Value = (Ram/1024/1024);
How do I make the memory and CPU usage of a given application the same as that shown in Task Manager?