Beispiel #1
0
        private void EnumerateNetworkAdapters()
        {
            PerformanceCounterCategory category = new PerformanceCounterCategory("Network Interface");

            foreach (string name in category.GetInstanceNames())
            {

            if (name == "MS TCP Loopback interface")
            { continue; }

            NetworkAdapter adapter = new NetworkAdapter(name);
            adapter.dlCounter = new PerformanceCounter("Network Interface", "Bytes Received/sec", name);
            adapter.ulCounter = new PerformanceCounter("Network Interface", "Bytes Sent/sec", name);
            this.adapters.Add(adapter);
            }
        }
Beispiel #2
0
 public void StartMonitoring(NetworkAdapter adapter)
 {
     if (!this.monitoredAdapters.Contains(adapter))
     {
     this.monitoredAdapters.Add(adapter);
     adapter.init();
     }
     this.timer.Enabled = true;
 }
Beispiel #3
0
 public void StopMonitoring(NetworkAdapter adapter)
 {
     if (this.monitoredAdapters.Contains(adapter))
     { this.monitoredAdapters.Remove(adapter); }
     if (this.monitoredAdapters.Count == 0)
     { this.timer.Enabled = false; }
 }
    /// <summary>
    /// Enumerates network adapters installed on the computer.
    /// </summary>
    private void EnumerateNetworkAdapters()
    {
        PerformanceCounterCategory category = new PerformanceCounterCategory("Network Interface");

        foreach (string name in category.GetInstanceNames())
        {
            // This one exists on every computer.
            if (name == "MS TCP Loopback interface")
            { continue; }
            // Create an instance of NetworkAdapter class, and create performance counters for it.
            NetworkAdapter adapter = new NetworkAdapter(name);
            adapter.dlCounter = new PerformanceCounter("Network Interface", "Bytes Received/sec", name);
            adapter.ulCounter = new PerformanceCounter("Network Interface", "Bytes Sent/sec", name);
            this.adapters.Add(adapter);			// Add it to ArrayList adapter
        }
    }