겨우 찾아낸 이 방법이 제일 나은것 같다.
출처 - https://ash84.net/2012/03/03/c-wmi-eb-a5-bc--ec-9d-b4-ec-9a-a9-ed-95-9c--ed-98-84-ec-9e-ac--eb-a9-94-eb-aa-a8-eb-a6-ac--ec-82-ac-ec-9a-a9-eb-9f-89--ea-b5-ac-ed-95-98-ea-b8-b0/
프로세스 메모리 사용량이 아닌 작업관리자에 나오는 시스템 메모리 사용량 체크 소스이다.
private uint GetTotalUsedMemory()
{
ManagementClass cls = new ManagementClass("Win32_OperatingSystem");
ManagementObjectCollection instances = cls.GetInstances();
foreach (ManagementObject info in instances)
{
int total_physical_memeory = int.Parse(info["TotalVisibleMemorySize"].ToString());
int free_physical_memeory = int.Parse(info["FreePhysicalMemory"].ToString());
int remain_physical_memory = total_physical_memeory - free_physical_memeory;
Console.WriteLine("Memory Information ================================");
Console.WriteLine("Total Physical Memory :{0:#,###} KB", info["TotalVisibleMemorySize"]);
Console.WriteLine("Free Physical Memory :{0:#,###} MB", info["FreePhysicalMemory"]);
Console.WriteLine("Memory Usage Percent = {0} %", 100 * remain_physical_memory / total_physical_memeory);
Console.WriteLine("Remain Physical Memory : {0:#,###}", remain_physical_memory);
return (uint)(remain_physical_memory / 1000);
}
return 0;
댓글 없음:
댓글 쓰기