public static double GetMemoryUsage() { MEMORY_STATUS_EX memInfo = new MEMORY_STATUS_EX(); memInfo.dwLength = (uint)Marshal.SizeOf(typeof(MEMORY_STATUS_EX)); GlobalMemoryStatusEx(ref memInfo); if (memInfo.ullTotalPhys <= 0) { return(0); } return((1 - (double)memInfo.ullAvailPhys / memInfo.ullTotalPhys) * 100); }
public static extern void GlobalMemoryStatusEx(ref MEMORY_STATUS_EX meminfo);