简体   繁体   English

确定导致NetworkChange事件触发的适配器

[英]Determine which adapter caused NetworkChange events to fire

I'm trying to write a service that will report back what adapter changed, when the events NetworkChange.NetworkAvailabilityChanged or NetworkChange.NetworkAddressChanged fire. 我正在尝试编写一个服务,该服务将在事件NetworkChange.NetworkAvailabilityChangedNetworkChange.NetworkAddressChanged触发时报告更改了什么适配器。 Every example I've found so far, show how to enumerate the nics, but not how to determine which adapter changed and subsequently fired the event. 到目前为止,我发现的每个示例都显示了如何枚举nics,但没有确定如何更改哪个适配器并随后触发了该事件。

Is this even possible? 这有可能吗? the only thing I've come up with so far, is to initially enumerate the adapters and store off the values in a collection of some sort. 到目前为止,我唯一想到的就是首先枚举适配器并将这些值存储在某种类型的集合中。 Then when one of these events fire, compare lists for differences. 然后,当这些事件之一触发时,比较列表以查找差异。 This might work, but seems unnaturally excessive to me. 这可能有效,但对我来说似乎过分自然。

"initially enumerate the adapters and store off the values in a collection of some sort. Then when one of these events fire, compare lists for differences" “首先枚举适配器,并将值存储在某种类型的集合中。然后,当其中一个事件触发时,比较差异列表”

Yes, do that. 是的,这样做。 It also has the advantage that you can check for changes periodically even absent a notification, and it is more testable. 它还具有的优点是,即使没有通知,您也可以定期检查更改,并且更具测试性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM