I\'ve created a performancecounter that can check the total memory usage in %, but the problem is that it doesn\'t give me the same value as in task manager shows me. for ex
Performance counters is not good idea. Use this code to get % of memory usage from Task Manager
var wmiObject = new ManagementObjectSearcher("select * from Win32_OperatingSystem");
var memoryValues = wmiObject.Get().Cast().Select(mo => new {
FreePhysicalMemory = Double.Parse(mo["FreePhysicalMemory"].ToString()),
TotalVisibleMemorySize = Double.Parse(mo["TotalVisibleMemorySize"].ToString())
}).FirstOrDefault();
if (memoryValues != null) {
var percent = ((memoryValues.TotalVisibleMemorySize - memoryValues.FreePhysicalMemory) / memoryValues.TotalVisibleMemorySize) * 100;
}