Search code examples
c#ethernet

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. 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.

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.


Solution

  • "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.