示例#1
0
 /// <summary>
 /// 启动监控指定网络适配器
 /// </summary>
 /// <param name="adapter"></param>
 public void Start(NetWorkAdapter adapter)
 {
     if (!_monitoredAdapters.Contains(adapter))
     {
         _monitoredAdapters.Add(adapter);
         adapter.Start(); //该适配器调用自己函数开始工作
     }
     base.Start();
 }
示例#2
0
 /// <summary>
 /// 停止监控指定网络适配器
 /// </summary>
 /// <param name="adapter"></param>
 public void Stop(NetWorkAdapter adapter)
 {
     if (_monitoredAdapters.Contains(adapter))
     {
         _monitoredAdapters.Remove(adapter);
     }
     if (_monitoredAdapters.Count == 0)
     {
         base.Stop();
     }
 }
示例#3
0
        //获取该计算机上的网络适配器
        private void GetNetAdapter()
        {
            var networkInterface = new PerformanceCounterCategory("Network Interface");

            foreach (string instanceName in networkInterface.GetInstanceNames())
            {
                if (instanceName == "MS TCP Loopback interface")
                {
                    continue;
                }
                var netWorkAdapter = new NetWorkAdapter(instanceName);
                _adaptersList.Add(netWorkAdapter);
            }
        }