Click here to Skip to main content
15,031,937 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi I write this code:

C#
PerformanceCounter pc = new PerformanceCounter(".NET CLR Networking", "Bytes Received", "System" );

            Console.WriteLine(pc.RawValue);
            Console.ReadLine();


Why i get error:
System.InvalidOperationException: 'Counter is single instance, instance name 'System' is not valid for this counter category.'


What I have tried:

I try by this link: and i can't
c# - How to monitor the network bandwidth usage of a specific application? - Stack Overflow[^]
Posted
Updated 1-Aug-17 8:44am

1 solution

You probably need to use another category 'Network Interface', see the answer here:
networking - How to display bytes received per second in C# - Stack Overflow[^]
But this is not process specific sadly ...

An alternative might be using the TCPView utility and using the output of that, see: TCPView for Windows - Windows Sysinternals | Microsoft Docs[^]
   
v3
Comments
Thomas Daniels 1-Aug-17 14:54pm
   
5. I have to add that the answer takes the first element of GetInstanceNames(), but when I tried it, I had to take the second element, or it wouldn't work.
RickZeeland 1-Aug-17 14:58pm
   
Yes, it depends on the hardware (network cards, Wifi etc) that you have ...
Armin.Engineer 1-Aug-17 15:37pm
   
Thanks , but i want get usage of application , in fact specific application .
RickZeeland 1-Aug-17 15:40pm
   
Use the command line version of TCPView, Tcpvcon and process the .CSV output of that in your program, good luck !
Armin.Engineer 3-Aug-17 12:11pm
   
How can i use? I think for network interface stack overflow link which You introduced in this topic , I want specific application like a messenger , I need know which what can i use category name and instance name , thanks
RickZeeland 3-Aug-17 12:34pm
   
No, the stackoverflow solution is not suitable for a specific application.
Use the command line version of TCPView: Tcpvcon and process the .CSV output of that in your program. You can use Process.Start() to call Tcpvcon from C#.
Armin.Engineer 3-Aug-17 17:21pm
   
Thanks , But i dont understand your solutaion , how can i get .CSV ? Can you simple explain ?
Armin.Engineer 6-Aug-17 11:22am
   
How can i solve this problem?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900