zoukankan      html  css  js  c++  java
  • 电脑运行状态

    using System;
    using System.Diagnostics;
    using System.Management;
    public class DeviceMonitor
    {
    
        static readonly PerformanceCounter cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
        static readonly PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Available MBytes");
        static readonly PerformanceCounter uptime = new PerformanceCounter("System", "System Up Time");
    
    
        /// <summary>
        /// 网络信息
        /// </summary>
        /// <returns></returns>
        public static bool GetInternetAvilable()
        {
            bool networkUp = System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable();
            return networkUp;
        }
    
        /// <summary>
        /// 系统运行时间
        /// </summary>
        /// <returns></returns>
        public static TimeSpan GetSystemUpTime()
        {
            uptime.NextValue();
            TimeSpan ts = TimeSpan.FromSeconds(uptime.NextValue());
            return ts;
        }
    
        /// <summary>
        /// 物理内存
        /// </summary>
        /// <returns></returns>
        public static string GetPhysicalMemory()
        {
            string str = null;
            ManagementObjectSearcher objCS = new ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem");
            foreach (ManagementObject objMgmt in objCS.Get())
            {
                str = objMgmt["totalphysicalmemory"].ToString();
            }
            return str;
        }
    
        /// <summary>
        /// CPU使用率
        /// </summary>
        /// <returns></returns>
        public static string getCurrentCpuUsage()
        {
            return cpuCounter.NextValue() + "%";
        }
    
        /// <summary>
        /// 内存使用
        /// </summary>
        /// <returns></returns>
        public static string getAvailableRAM()
        {
            return ramCounter.NextValue() + "MB";
        }
    }
    

      

  • 相关阅读:
    [转][LeetCode]Longest Common Prefix ——求字符串的最长公共前缀
    [转]最长回文子串——4种解法
    [转]通过金矿模型介绍动态规划
    一句话说清楚什么是闭包函数
    [转]as3事件流机制彻底理解
    Eclipse 快捷键
    文件打包与解压缩
    第5节 环境变量与文件查找
    vim的多标签
    java思维导图
  • 原文地址:https://www.cnblogs.com/lhlong/p/11057818.html
Copyright © 2011-2022 走看看