0

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

enter image description here

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);
 }
EvrySad
  • 1
  • 2

1 Answers1

-1
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
}

Try this question : retrieve-process-network-usage

Jophy job
  • 1,924
  • 2
  • 20
  • 38
  • 1
    I already tried that code and it's just showing the IO read and write bytes not the "Send and Receive Bytes" , I want to read that to compute the total packets usage of 1 specific process – EvrySad Jan 24 '18 at 03:17