我正在尝试获取实际的空闲内存。使用性能计数器似乎是最简单的解决方案。它在我的编码机上工作得很好,不幸的是我在目标计算机上得到了一个异常。我用的是Windows XP和.NET 3.5,你能帮我吗?
代码:
namespace TestConsole
{
class Program
{
static void Main(string[] args)
{
PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Available Bytes");
}
}
}例外:
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发布于 2012-06-25 21:52:05
我无法解决底层问题,但有一个解决方法,不使用PerformanceCounter,而是API调用,请参阅http://www.codeproject.com/Articles/1285/Calling-API-functions-using-C。
发布于 2012-06-18 16:44:48
异常消息说明了一切:
类别不存在。
平均类别"Memory“不存在。
https://stackoverflow.com/questions/11079124
复制相似问题