读取性能计数器从C#:实例没有在指定的类别中存在 [英] Reading performance counter from C#: Instance does not exist in the specified category

查看:1135
本文介绍了读取性能计数器从C#:实例没有在指定的类别中存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从正在运行的.NET 4应用程序读取了一些性能计数器,从另一个.NET 4的应用程序。

I'm trying to read a number of performance counters from a running .NET 4 application, from another .NET 4 application.

一些计数器,如处理\%处理器时间 Process \ Private字节做工精细。然而,当我试图从的.NET类,如 .NET CLR内存\#第0集,我得到下面的异常任何一个读取性能计数器

Some counters, such as Process\% Processor Time and Process\Private Bytes work fine. However, as soon as I try to read a performance counter from one of the .NET categories, such as .NET CLR Memory\# Gen 0 Collections, I get the following exception:

Instance 'MyApplication' does not exist in the specified Category

当我打电话:

new PerformanceCounterCategory(".NET CLR Memory").GetInstanceNames()

它返回一个非常小的实例集,并且所有MyApplication确实不在列表中。但是,当我看着我的性能计数器性能监视器情况下我看到有对同一类别的清单/计数器是更长的时间,确实包括MyApplication的。

It returns a very small set of instances, and MyApplication is indeed not in the list. However, when I look at my performance counters in perfmon, the list of instances I see there for the same category/counter is much longer and DOES include MyApplication.

有谁知道为什么.NET柜台看不到我的应用程序?

Does anyone know why the .NET counters are not visible to my application?

(注:监视应用程序的开始的由监控应用程序,所以他们肯定是在同一个用户帐户运行我也想开始我的监视应用程序作为管理员,加入我的帐户添加到性能监视器。 Users组,没有效果。)

(Note: The monitored application is started by the monitoring application, so they definitely run in the same user account. I also tried starting my monitoring application as Administrator and adding my account to the Performance Monitor Users group, to no effect.)

推荐答案

有两种设置一个项目,可以是有关你的问题。

There are two settings for a project that can be relevant to your problem.

首先,项目+属性,生成标签,平台目标。在一台具有64位的操作系统,将其设置为86将得到您的实例的名称做一个列表的没有的包括64位进程。 PERFMON.EXE是一个64位的过程中,它显示了所有情况下,32位和64位应用程序。由平台目标设置值为anycpu获得同样的效果,这是不是默认了对Visual Studio 2010中取消选中preFER 32位,如果你看到它。

First and foremost, Project + Properties, Build tab, Platform target. On a machine with a 64-bit operating system, setting this to x86 will get you a list of instance names that do not include 64-bit processes. Perfmon.exe is a 64-bit process, it shows all instances, both 32-bit and 64-bit apps. Get the same behavior by setting the Platform target to AnyCPU, that's not the default anymore on Visual Studio 2010. Untick "Prefer 32-bit" if you see it.

二是项目+属性,调试选项卡,启用在Visual Studio宿主进程选项。勾选后,如果在调试命名yourapp.vshost.exe而不是yourapp.exe过程。这也影响了实例名,它会被yourapp.vshost。不太可能会在特定情况下的问题。

Second is Project + Properties, Debug tab, "Enable the Visual Studio hosting process" option. When checked, you are debugging an process named yourapp.vshost.exe instead of yourapp.exe. That also affects the instance name, it will be yourapp.vshost. Not likely to be the problem in your specific case.

请务必使用这一重要信息更新您的问题,如果这个猜测是不准确的。

Be sure to update your question with this essential info if this guess wasn't accurate.

这篇关于读取性能计数器从C#:实例没有在指定的类别中存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆