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";
        }
    }
    

      

  • 相关阅读:
    mysql一些基本操作
    redis的简单使用2
    redis的基本conf
    redis的简单使用
    $.ajax()方法详解(转)
    流行的9个Java框架介绍: 优点、缺点等等
    数据库查询,显示为树形结构(easyui+SSM)
    JAVA-汉字转换成汉语拼音(pinyin4j-2.5.0-sources.jar)
    Jquery EasyUI 中ValidateBox验证框使用讲解(转)
    EasyUI验证扩展
  • 原文地址:https://www.cnblogs.com/lhlong/p/11057818.html
Copyright © 2011-2022 走看看