首页 > 代码库 > C# 获得系统的CPU和内存信息

C# 获得系统的CPU和内存信息

static void Main(string[] args)
        {
            PerformanceCounter pcCPULoad = new PerformanceCounter("Processor", "% Idle Time", "_Total");
            ComputerInfo ci = new ComputerInfo();
            //物理内存
            ulong me = ci.TotalPhysicalMemory;
            ulong av = ci.AvailablePhysicalMemory;
            while (true)
            {
                Thread.Sleep(500);
                Console.Write("CPU"+(100 - Math.Round(pcCPULoad.NextValue(), 0)));
                Console.Write("系统物理内存(M):" + ci.TotalPhysicalMemory / 1024 / 1024);
                Console.Write("系统虚拟内存(M):" + ci.TotalVirtualMemory / 1024 / 1024);
                Console.Write("可用物理内存(M):" + ci.AvailablePhysicalMemory / 1024 / 1024);
                Console.Write("可用虚拟内存(M):" + ci.AvailableVirtualMemory / 1024 / 1024);
                Console.WriteLine("");
            }
        }

 

C# 获得系统的CPU和内存信息