Counter是单个实例,实例名称“WebDev.WebServer40”对此计数器类别无效

时间:2012-04-17 12:05:45

标签: c# .net performance performancecounter

我正在尝试使用内存性能计数器:

System.Diagnostics.PerformanceCounter theMemCounter = 
    new System.Diagnostics.PerformanceCounter("Memory", "Available MBytes",
    System.Diagnostics.Process.GetCurrentProcess().ProcessName, true);

var memStart = theMemCounter.NextValue();

但在第二行我收到以下错误:

Counter is single instance, instance name 'WebDev.WebServer40' is not valid for this counter category.

有什么问题?

1 个答案:

答案 0 :(得分:2)

Ottoni,我认为你不能为这个特定的性能计数器指定一个进程,因为它监视整个系统的可用内存。

也许您正在寻找的perfcounter是“.NET CLR内存(INSTANCE)#Bytes in all Heaps”或.NET CLR Memory类别中的其他一些,它能够监视所有或指定的内存使用情况。净申请。

此处有关此类别的更多信息:http://msdn.microsoft.com/en-us/library/x2tyfybc.aspx

- 编辑

<强>解决方案:

System.Diagnostics.PerformanceCounter theMemCounter =
    new System.Diagnostics.PerformanceCounter("Process", "Working Set",
    System.Diagnostics.Process.GetCurrentProcess().ProcessName);

var memStart = theMemCounter.NextValue() / 1024 / 1024;
相关问题