如何在C#中显示每秒接收的字节数

时间:2015-08-25 18:36:14

标签: c# networking byte performancecounter

我试图每秒显示收到的字节数,并让它们每秒显示在控制台中一次。一旦达到.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);
}

1 个答案:

答案 0 :(得分:2)

很抱歉在有人做过之后回答,但是这有什么用呢?

JSON.stringify(my_obj);

来自here