【发布时间】:2014-05-31 05:40:46
【问题描述】:
我试过这段代码:
public static string GetProcessMemoryUsage(string processName)
{
while (true)
{
PerformanceCounter performanceCounter = new PerformanceCounter();
performanceCounter.CategoryName = "Process";
performanceCounter.CounterName = "Working Set";
performanceCounter.InstanceName = Process.GetCurrentProcess().ProcessName;
processName = ((uint)performanceCounter.NextValue() / 1024).ToString(processName);
return processName;
}
}
如果进程名称例如:BFBC2Game 然后 GetProcessMemoryUsage 方法只返回名称:BFBC2Game 我希望它返回我在 Windows 中的任务管理器中的内存使用值编号,例如当我运行我在 BFBC2Game 上看到的任务管理器时:78% 和 198.5MB 内存使用量。
这就是我想在返回的字符串 processName 中得到的:78% 和 198.5MB 类似的东西。并且它会在循环中一直得到更新。和任务管理器中的一样。
【问题讨论】:
标签: c# winforms performancecounter