C#资源监视器获取网络活动值

时间:2018-01-23 08:56:00

标签: c# networking monitoring

我只想使用C#

在我的Windows应用程序表单上显示此过程的值

this paper

我尝试使用PerformanCounter课程,但我无法弄明白。

 var perfCounter = new PerformanceCounter("Network Interface", "Bytes Received/sec", "chrome");
 // Initialize to start capturing
 perfCounter.NextValue();

 for (int i = 0; i < 20; i++)
 {
     // give some time to accumulate data
     Thread.Sleep(1000);

     float receive = perfCounter.NextValue() / Environment.ProcessorCount;

     Console.WriteLine("Bytes Receive/sec: " + receive);
 }

1 个答案:

答案 0 :(得分:0)

string pn = "MyProcessName.exe";
var readOpSec  = new PerformanceCounter("Process","IO Read Operations/sec", pn);
var writeOpSec = new PerformanceCounter("Process","IO Write Operations/sec", pn);
var dataOpSec  = new PerformanceCounter("Process","IO Data Operations/sec", pn);
var readBytesSec = new PerformanceCounter("Process","IO Read Bytes/sec", pn);
var writeByteSec = new PerformanceCounter("Process","IO Write Bytes/sec", pn);
var dataBytesSec = new PerformanceCounter("Process","IO Data Bytes/sec", pn);

var counters = new List<PerformanceCounter>
                {
                readOpSec,
                writeOpSec,
                dataOpSec,
                readBytesSec,
                writeByteSec,
                dataBytesSec
                };

// get current value
foreach (PerformanceCounter counter in counters)
{
    float rawValue = counter.NextValue();

    // display the value
}

试试这个问题:retrieve-process-network-usage