首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >创建PerformanceCounter时的InvalidOperationException

创建PerformanceCounter时的InvalidOperationException
EN

Stack Overflow用户
提问于 2012-06-18 16:17:01
回答 2查看 2.6K关注 0票数 0

我正在尝试获取实际的空闲内存。使用性能计数器似乎是最简单的解决方案。它在我的编码机上工作得很好,不幸的是我在目标计算机上得到了一个异常。我用的是Windows XP和.NET 3.5,你能帮我吗?

代码:

代码语言:javascript
复制
namespace TestConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Available Bytes");
        }
    }
}

例外:

代码语言:javascript
复制
Unhandled Exception: System.InvalidOperationException: Category does not exist.
   at System.Diagnostics.PerformanceCounterLib.CounterExists(String machine, String category, String counter)
   at System.Diagnostics.PerformanceCounter.Initialize()
   at System.Diagnostics.PerformanceCounter..ctor(String categoryName, String counterName, String instanceName, Boolean
readOnly)
   at System.Diagnostics.PerformanceCounter..ctor(String categoryName, String counterName)
   at TestConsole.Program.Main(String[] args) in D:\Projektarbeit\Bachelorarbeit\VS2010\Projekte\DiagStationControllerTe
stConsoleV1\TestConsole\Program.cs:line 15
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-06-25 21:52:05

我无法解决底层问题,但有一个解决方法,不使用PerformanceCounter,而是API调用,请参阅http://www.codeproject.com/Articles/1285/Calling-API-functions-using-C

票数 0
EN

Stack Overflow用户

发布于 2012-06-18 16:44:48

异常消息说明了一切:

类别不存在。

平均类别"Memory“不存在。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11079124

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档