C#资源监视器获取网络活动值 [英] C# Resource Monitor get network activity values

查看:579
本文介绍了C#资源监视器获取网络活动值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想使用C#在Windows应用程序窗体上显示此过程的值

I just want to display the values of this process on my windows app form using C#

我使用PerformanCounter类尝试了此操作,但无法弄清楚.

I tried this using PerformanCounter class but I can't figure it out.

 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);
 }

推荐答案

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

这篇关于C#资源监视器获取网络活动值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆