J4N
J4N

Reputation: 20717

Be informed when a network cable is plugged in / Wifi connected

I'm implementing in C# a discovery protocol (DNS-SD). I've a small problem: when my program is running, I need to detect when a new connection is established (network cable plugged or wifi joined), to announce myself on those network too.

But how to detect this? I've seen some code to get the current state of a network card, but no event, and I want to avoid to make some polling on the network cards states.

Upvotes: 9

Views: 2147

Answers (1)

Carsten
Carsten

Reputation: 11606

You can use the GetIstNetworkAvailable-method to check if there is a network connection at all. Whenever it changes the NetworkAvailabilityChanged event get's fired. For more information see this question.

If you want to track the availability of different NetworkInterfaces here is an sample on how to do this.

Upvotes: 4

Related Questions