gpt4 book ai didi

c# - 测量互联网上消耗的 mb

转载 作者:行者123 更新时间:2023-11-30 17:40:18 24 4
gpt4 key购买 nike

我想通过代码获取互联网上消耗的 MB 数..

我知道它可以手动完成:设置 -> 网络和互联网 -> 数据使用(Windows 10)

照片: Settings -> Network & Internet -> Data Usage (Windows 10)

但是我怎样才能通过代码找到它呢?

我想要整个系统的编号,而不仅仅是我的应用程序。

例如,我希望我的代码显示:本月使用的 GB 为 3.21!

最佳答案

您可以尝试以下代码段,它会为您提供发送和接收的总数据。你只需要总结一下:

private static void GetTrafficStatistics()
{
PerformanceCounterCategory performanceCounterCategory = new PerformanceCounterCategory("Network Interface");
string instance = performanceCounterCategory.GetInstanceNames()[0]; // 1st NIC !
PerformanceCounter performanceCounterSent = new PerformanceCounter("Network Interface", "Bytes Sent/sec", instance);
PerformanceCounter performanceCounterReceived = new PerformanceCounter("Network Interface", "Bytes Received/sec", instance);

for (int i = 0; i < 10; i++)
{
Console.WriteLine("bytes sent: {0}k\tbytes received: {1}k", performanceCounterSent.NextValue() / 1024, performanceCounterReceived.NextValue() / 1024);
Thread.Sleep(500);
}
}

PS:它正在使用System.Diagnostics.dll

希望对您有所帮助。

关于c# - 测量互联网上消耗的 mb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34461456/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com