在 C# 中检测网络连接速度和带宽使用情况

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/566139/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 08:24:23  来源:igfitidea点击:

Detecting network connection speed and bandwidth usage in C#

c#networkingperformancebandwidthdetect

提问by Mats

Is there a way to detect the network speed and bandwidth usage in C#? Even pointers to open-source components are welcome.

有没有办法在 C# 中检测网络速度和带宽使用情况?甚至欢迎指向开源组件的指针。

采纳答案by GWLlosa

Try using the System.Net.NetworkInformation classes. In particular, System.Net.NetworkInformation.IPv4InterfaceStatisticsought to have some information along the lines of what you're looking for.

尝试使用 System.Net.NetworkInformation 类。特别是,System.Net.NetworkInformation.IPv4InterfaceStatistics应该有一些与您要查找的内容相符的信息。

Specifically, you can check the bytesReceivedproperty, wait a given interval, and then check the bytesReceivedproperty again to get an idea of how many bytes/second your connection is processing. To get a good number, though, you should try to download a large block of information from a given source, and check then; that way you should be 'maxing' the connection when you do the test, which should give more helpful numbers.

具体来说,您可以检查该bytesReceived属性,等待给定的时间间隔,然后bytesReceived再次检查该属性以了解您的连接正在处理多少字节/秒。但是,要获得一个好的数字,您应该尝试从给定的来源下载大量信息,然后进行检查;这样,您应该在进行测试时“最大化”连接,这应该会提供更多有用的数字。

回答by Randolpho

You should be able to calculate everything you need from the IPGlobalStatisticsclass.

您应该能够从IPGlobalStatistics类中计算出您需要的所有内容。