zoukankan      html  css  js  c++  java
  • c#监测电脑状态

     1 public class DeviceMonitor
     2     {
     3 
     4         static readonly PerformanceCounter cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
     5         static readonly PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Available MBytes");
     6         static readonly PerformanceCounter uptime = new PerformanceCounter("System", "System Up Time");
     7 
     8 
     9         public static bool GetInternetAvilable()
    10         {
    11             bool networkUp = System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable();
    12             return networkUp;
    13         }
    14 
    15         public static TimeSpan GetSystemUpTime()
    16         {
    17             uptime.NextValue();
    18             TimeSpan ts = TimeSpan.FromSeconds(uptime.NextValue());
    19             return ts;
    20         }
    21 
    22         public static string GetPhysicalMemory()
    23         {
    24             string str = null;
    25             ManagementObjectSearcher objCS = new ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem");
    26             foreach (ManagementObject objMgmt in objCS.Get())
    27             {
    28                 str = objMgmt["totalphysicalmemory"].ToString();
    29             }
    30             return str;
    31         }
    32 
    33         public static string getCurrentCpuUsage()
    34         {
    35             return cpuCounter.NextValue() + "%";
    36         }
    37 
    38         public static string getAvailableRAM()
    39         {
    40             return ramCounter.NextValue() + "MB";
    41         }
    42     }
    View Code

    c# 监测电脑状态,CPU使用率,物理内存使用,开机时间,网络状态

  • 相关阅读:
    RecycleView使用心得【2】
    URL解析
    CSS 动画总结
    包含块 width 和 height 值的总结
    JS 获取页面大小
    常见跨域方法原理及其用例
    CSS 计数器
    JS 对象总结
    JS 原型以及原型链
    关于未能找到源文件“.NETFramework,Version=v4.0.AssemblyAttributes.cs”问题
  • 原文地址:https://www.cnblogs.com/congqiandehoulai/p/5851327.html
Copyright © 2011-2022 走看看