I'm creating a C# WinForm Application which will display Network Activity (Bytes Received / Bytes Sent) for a given Process (For Example: Process name 's chrome.exe
) and Speed in Megabyte/s generated by the Process.
My application uses Performance Counter Class to get the Process activities like IO Read Bytes/sec
for received bytes and IO Writes Bytes/sec
for sent bytes. But, it's giving me 0 Bytes as a result, which's very weird because chrome.exe
is running and its definitely using some bytes data.
Researches that I've tried to find the solution are:
- https://stackoverflow.com/a/17026417/5377037
- C# Resource Monitor get network activity values
- https://www.c-sharpcorner.com/forums/i-want-to-develop-resource-monitor-desktop-application
Here is some code that I'm using :
PerformanceCounter PC = new PerformanceCounter();
PC.CategoryName = "Process";
PC.CounterName = "IO Read Bytes/sec";
PC.InstanceName = "chrome";
PC.ReadOnly = true;
Console.WriteLine("Bytes Receieved: " + Math.Round(PC.NextValue()));
PC.CounterName = "IO Write Bytes/sec";
Console.WriteLine("Bytes Sent: " + Math.Round(PC.NextValue()));
Results:
Bytes Received: 0
Bytes Sent: 0