【问题标题】:Counter is single instance, instance name 'WebDev.WebServer40' is not valid for this counter category计数器是单个实例,实例名称“WebDev.WebServer40”对此计数器类别无效
【发布时间】:2012-04-28 18:33:33
【问题描述】:

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

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.

有什么问题?

【问题讨论】:

  • 如果您打开 perfmon,您会在 Memory 类别中看到该计数器吗?
  • 你说的是CategoryName这个属性吗?如果是,这里是:CategoryName = "Memory".

标签: c# .net performance performancecounter


【解决方案1】:

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

也许您正在寻找的 perfcounter 是“.NET CLR Memory(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;

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-20
  • 2016-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多