zoukankan      html  css  js  c++  java
  • 获取当前电脑的cpu使用率、内存使用率

    https://www.cnblogs.com/Chary/p/7771365.html

    http://www.cnblogs.com/zl1991/p/4679461.html

    要关注几个类 PerformanceCounter 用来针对cpu  ;ComputerInfo 用来针对内存

    using Microsoft.VisualBasic.Devices;
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace CpuAndMemory
    {
        class Program
        {
            //PerformanceCounter 性能计数器
            public static PerformanceCounter cpu;
    
            //来自程序集 Microsoft.VisualBasic.dll 手动引用
            public static ComputerInfo cInfo;
            static void Main(string[] args)
            {
                cpu = new PerformanceCounter("Processor", "% Processor Time", "_Total");
    
                //---------------内存相关---------------
                cInfo = new ComputerInfo();
                Console.WriteLine("当前计算机的总内存大小为"+cInfo.TotalPhysicalMemory/1024/1024+"G");
                Console.WriteLine("当前计算机的虚拟内存大小为:"+cInfo.TotalVirtualMemory / 1024 / 1024 + "G");
                Console.WriteLine("当前计算机的虚拟内存大小为:" + cInfo.TotalVirtualMemory);
                Console.WriteLine("当前计算机的可用物理内存大小为:" + cInfo.AvailablePhysicalMemory);
                Console.WriteLine("当前计算机的可用虚拟内存大小为:" + cInfo.AvailableVirtualMemory);
                //---------------内存相关---------------
                Console.ReadKey();
            }
        }
    }
  • 相关阅读:
    Spring事务传播机制
    关于MyBatis-Like的模糊查询,">"、"<"等需转义字符描述
    MyBatis中if
    报错(持续.....)
    爬虫报错(持续.....)
    django的timezone问题
    dispatch
    django + uwsgi + nginx 实现高并发环境部署 及 报错处理
    虚拟机问题(持续更新.......)
    Tornado
  • 原文地址:https://www.cnblogs.com/wholeworld/p/10041893.html
Copyright © 2011-2022 走看看