Memory 类别不存在。在为Ram使用创建性能计数器时

Memory 类别不存在。在为Ram使用创建性能计数器时,memory,c++-cli,cpu-usage,performancecounter,Memory,C++ Cli,Cpu Usage,Performancecounter,这是代码,我正在尝试运行以获取内存使用率 int main(array<System::String ^> ^args) { PerformanceCounter^ ramCounter; try { Console::WriteLine(L"Hello World"); ramCounter = gcnew PerformanceCounter("Memory", "Avail

这是代码,我正在尝试运行以获取内存使用率

int main(array<System::String ^> ^args)
{
    PerformanceCounter^ ramCounter;
    try
    {
        Console::WriteLine(L"Hello World");
        ramCounter = gcnew PerformanceCounter("Memory", "Available MBytes");
        Console::WriteLine(L"Memory usgae:"+ramCounter->NextValue()+L"MB");
    }
    catch(Exception^ e)
    {
        Console::WriteLine("Error Message: "+e->Message);
        Console::WriteLine(e->StackTrace);
    }
    finally
    {
        if(ramCounter!=nullptr)
        {
            ramCounter->Close();
        }
        Console::WriteLine("Press any key to exit");
        Console::ReadLine();
    }
    return 0;
}
int main(数组^args)
{
性能计数器^随机计数器;
尝试
{
控制台::WriteLine(L“Hello World”);
ramCounter=gcnewperformancecounter(“内存”、“可用MB”);
控制台::WriteLine(L“内存usgae:+ramCounter->NextValue()+L“MB”);
}
捕获(异常^e)
{
控制台::WriteLine(“错误消息:”+e->Message);
控制台::WriteLine(e->StackTrace);
}
最后
{
if(ramCounter!=nullptr)
{
ramCounter->Close();
}
控制台::WriteLine(“按任意键退出”);
控制台::ReadLine();
}
返回0;
}
但我有点例外

错误消息:类别不存在

错误消息堆栈跟踪:
在System.Diagnostics.PerformanceCounterLib.CounterExists(字符串 机器、字符串类别、字符串计数器) System.Diagnostics.PerformanceCounter.InitializeImpl()位于 System.Diagnostics.PerformanceCounter..ctor(字符串类别名称, 字符串计数器名、字符串实例名、布尔值只读) System.Diagnostics.PerformanceCounter..ctor(字符串类别名称, 中的主(字符串[]args)处的字符串计数器名称) c:\users\documents\visual studio 2012\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp:line 三十一


对此有任何想法。

这可能是由于本地化问题。在我的机器上,你的代码也不起作用,因为它的语言是德语。因此,我必须使用

 gcnew PerformanceCounter("Arbeitsspeicher", "Verfügbare MB")
您可以通过浏览中的可用性能计数器来查找本地化名称


还有一种方法可以以独立于语言的方式检索计数器数据。有关详细信息,请参阅。

这可能会帮助您确定这是C#(如标签中所述)?看起来更像C++。@古德纳德拉普,这是微软、C++和CLI的C++的一个特殊的“版本”。