/// <summary> /// 启动监控指定网络适配器 /// </summary> /// <param name="adapter"></param> public void Start(NetWorkAdapter adapter) { if (!_monitoredAdapters.Contains(adapter)) { _monitoredAdapters.Add(adapter); adapter.Start(); //该适配器调用自己函数开始工作 } base.Start(); }
/// <summary> /// 停止监控指定网络适配器 /// </summary> /// <param name="adapter"></param> public void Stop(NetWorkAdapter adapter) { if (_monitoredAdapters.Contains(adapter)) { _monitoredAdapters.Remove(adapter); } if (_monitoredAdapters.Count == 0) { base.Stop(); } }
//获取该计算机上的网络适配器 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); } }