Is there a way to detect the network speed and bandwidth usage in C#? Even pointers to open-source components are welcome.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Try using the System.Net.NetworkInformation classes. In particular, System.Net.NetworkInformation.IPv4InterfaceStatistics
ought to have some information along the lines of what you're looking for.
Specifically, you can check the bytesReceived
property, wait a given interval, and then check the bytesReceived
property 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.
回答2:
You should be able to calculate everything you need from the IPGlobalStatistics class.