Home
Manage Your Code
Snippet: NetworkTraffic (C#)
Title: NetworkTraffic Language: C#
Description: Get network adapter traffic in bytes Views: 406
Author: Gerson Amorim Date Added: 7/11/2012
Copy Code  
1         InstanceIndex = 0;
2
3         performanceCounterCategory = new PerformanceCounterCategory("Network Interface");
4
5         performanceCounterBytesReceived = new PerformanceCounter("Network Interface", "Bytes Received/sec");
6         performanceCounterBytesReceived.InstanceName = performanceCounterCategory.GetInstanceNames()[instanceIndex];
7         performanceCounterBytesReceived.MachineName = performanceCounterCategory.MachineName;
8         performanceCounterBytesReceived.ReadOnly = true;
9
10         performanceCounterCurrentBandwidth = new PerformanceCounter("Network Interface", "Current Bandwidth");
11         performanceCounterCurrentBandwidth.InstanceName = performanceCounterCategory.GetInstanceNames()[instanceIndex];
12         performanceCounterCurrentBandwidth.MachineName = performanceCounterCategory.MachineName;
13         performanceCounterCurrentBandwidth.ReadOnly = true;