我正在尝试获取实际的可用内存。使用性能计数器似乎是最简单的解决方案。它在我的编码机上工作得很好,不幸的是我在目标计算机上得到了一个异常。我使用 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