如何使用 .NET 在 Windows Server 2012 中获取提交的内存

How to get Committed Memory in Windows Server 2012 using .NET

这是我获取总内存和已用内存的方式:

PerformanceCounter ramAvailableCounter = new PerformanceCounter("Memory", "Available MBytes");
var ramUsedMB = ramAvailableCounter.NextValue();

var ramTotalMB = new Microsoft.VisualBasic.Devices.ComputerInfo().TotalPhysicalMemory / 1024 / 1024;

var ramPercentageLeft = (ramUsedMB * 100) / ramTotalMB;



但是我怎样才能得到下面显示的 "Committed" 内存呢?
不幸的是,我们使用的应用程序在只有大约 15GB 可用空间时抛出异常,我想在足够接近时发送通知。

可按如下方式进行:

PerformanceCounter percCommittedBytesInUseCounter = new PerformanceCounter("Memory", "% Committed Bytes In Use");