如何获得Ping,CPU使用率和内存使用C# [英] How to get Ping, CPU usage, And Memory used C#
本文介绍了如何获得Ping,CPU使用率和内存使用C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好我有 3 标签 Ping , CPU ,内存,我想显示我的cpu使用情况在它内部,内存使用和ping所有标签必须每1分钟更新一次
任何人都可以帮忙吗?
我不知道怎么做。
Hi guys i have 3labels Ping,CPU,Memory and i want to display my cpu usage inside it , memory usage and ping all labels must get updated every 1 minute
Can anyone help?
Im not sure how.
推荐答案
CPU和mem只是WMI和PerformanceCounter对象:
CPU and mem are just WMI and PerformanceCounter objects:
// CPU
ManagementObjectSearcher cpuSearch = new ManagementObjectSearcher(@"\root\CIMV2",
"SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name=\"_Total\"");
ManagementObjectCollection moc = cpuSearch.Get();
ManagementObject mo = moc.Cast<managementobject>().First();
string cpu = mo["PercentIdleTime"].ToString();
// MEM
PerformanceCounter memCounter = new PerformanceCounter("Memory", "Available MBytes");
string mem = memCounter.NextValue().ToString();
</managementobject>
Ping不是你可以测量的东西:它是特定服务器的往返时间值,它测量两台机器的连接速度及其响应时间。你不能只说我的ping是nn,因为它完全没有意义!它需要一台服务器来测量它。
Ping is not something you can just measure: it's a round trip time value to a specific server, and it measures the connection speed of both machines and their response times. You can't just say "My ping is nn" because it is completely meaningless! It needs a server to measure it against.
这篇关于如何获得Ping,CPU使用率和内存使用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文