How to check memory consumption in c#
An operating system is software/firmware that makes a computer system's hardware usable, and implements and/or manages the resources, file systems, processes, user interfaces, services, ... available on the computer system. The CIM_OperatingSystem class represents a computer operating system, which is made up of software and firmware that make a computer system's hardware usable.
Here is how you can learn the total physical memory installed, current memory consumption, virtual memory usage, etc.
// Add System.Management to references
var winQuery = new ObjectQuery("SELECT * FROM CIM_OperatingSystem");
var searcher = new ManagementObjectSearcher(winQuery);
foreach (var item in searcher.Get())
{
Console.WriteLine("Free Physical Memory: {0}", item["FreePhysicalMemory"]);
Console.WriteLine("Total Physical Memory: {0}", item["TotalVisibleMemorySize"]);
Console.WriteLine("Free Virtual Memory: {0}", item["FreeVirtualMemory"]);
Console.WriteLine("Total Virtual Memory: {0}", item["TotalVirtualMemorySize"]);
}