Original: C # monitor PC status
1 Public classDevicemonitor2 {3 4 Static ReadOnlyPerformanceCounter Cpucounter =NewPerformanceCounter ("Processor","% Processor time","_total");5 Static ReadOnlyPerformanceCounter Ramcounter =NewPerformanceCounter ("Memory","Available MBytes");6 Static ReadOnlyPerformanceCounter uptime =NewPerformanceCounter ("System","System up time");7 8 9 Public Static BOOLgetinternetavilable ()Ten { One BOOLNetworkup =System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable (); A returnNetworkup; - } - the Public StaticTimeSpan getsystemuptime () - { - uptime. NextValue (); -TimeSpan ts =timespan.fromseconds (uptime. NextValue ()); + returnts; - } + A Public Static stringgetphysicalmemory () at { - stringstr =NULL; -ManagementObjectSearcher OBJCS =NewManagementObjectSearcher ("SELECT * from Win32_ComputerSystem"); - foreach(ManagementObject objmgmtinchobjcs.get ()) - { -str = objmgmt["TotalPhysicalMemory"]. ToString (); in } - returnstr; to } + - Public Static stringgetcurrentcpuusage () the { * returnCpucounter.nextvalue () +"%"; $ }Panax Notoginseng - Public Static stringGetavailableram () the { + returnRamcounter.nextvalue () +"MB"; A } the}
View Code
C # Monitor PC status, CPU usage, physical memory usage, boot time, network status
C # monitor PC status