我试图每秒显示收到的字节数,并让它们每秒显示在控制台中一次。一旦达到.nextvalue,我就会看到无效的操作异常。
PerformanceCounter NetworkDownSpeed = new PerformanceCounter("Network Interface", "Bytes Received/sec");
float CurrentNetworkDownSpeed = (int)NetworkDownSpeed.NextValue();
while (true)
{
Console.WriteLine("Current Network Download Speed: {0}MB", CurrentNetworkDownSpeed);
Thread.Sleep(1000);
}