I have a process
Process p = new Process();
p.StartInfo = new ProcessStartInfo("java", -jar test.jar);
and I need get RAM, CPU of process p
is used in realtime
my code to get RAM is used but not in realtime:
while(true) {
txtRamIsUsed.Text = BytesToReadableValue(p.PrivateMemorySize64);
}
public string BytesToReadableValue(long number)
{
List<string> suffixes = new List<string> { " B", " KB", " MB", " GB", " TB", " PB" };
for (int i = 0; i < suffixes.Count; i++)
{
long temp = number / (int)Math.Pow(1024, i + 1);
if (temp == 0)
{
return (number / (int)Math.Pow(1024, i)) + suffixes[i];
}
}
return number.ToString();
}