本文介绍了特定过程的性能计数器功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HI朋友,
i我正在使用下面提到的功能是我计算的整体CPU使用率
但是我希望功能在i中我会传递进程名称作为参数并获取cpu使用率,Ram使用率和胎面。
请帮助完成这项任务
HI Friends,
i am using function below mention is which i have calculate overall CPU usage
but i want function in i will pass process name as parameter and get cpu usage, Ram usage and tread.
please help for this task
private void CalcCpu()
{
// refresh delay 1.5 seconds
int RefreshInterval = 1500;
// keeps the previous usage value.
long OldRawUsageValue = GetCurrentUsageValue();
// keeps the current usage value.
long NewRawUsageValue;
// holds the cpu usage in a friendly reading way.
string CpuUsage;
Thread.Sleep(RefreshInterval);
while (KeepCalculation)
{
NewRawUsageValue = GetCurrentUsageValue();
CpuUsage = ((int)((NewRawUsageValue - OldRawUsageValue) /
RefreshInterval)).ToString() + "%";
Thread.Sleep(RefreshInterval);
OldRawUsageValue = NewRawUsageValue;
}
}
推荐答案
Imports System.Diagnostics
If PerformanceCounterCategory.InstanceExists( applicationInstanceName , "% Processor Time") Then
' Code to use that performance counter....
End If
我建议你不要使用Thread.Sleep虽然...
I would recommend you do NOT use Thread.Sleep though...
这篇关于特定过程的性能计数器功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!