InvalidOperationException when creating PerformanceCounter

i'm trying to get the actual free memory. It seems to be the easiest solution to use Performance Counters. It works totally fine on my Coding Machine, unfortunately I get an Exception on the target Computer. I use Windows XP an .NET 3.5 Can you please help me?

Code:

namespace TestConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Available Bytes");
        }
    }
}

Exception:

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:ProjektarbeitBachelorarbeitVS2010ProjekteDiagStationControllerTe
stConsoleV1TestConsoleProgram.cs:line 15

Exception message says everything:

Category does not exist.

Mean category "Memory" does not exist.


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

链接地址: http://www.djcxy.com/p/62936.html

上一篇: 使用RSA签署Xml文档

下一篇: 创建PerformanceCounter时发生InvalidOperationException