As mentioned above, you need to use the Network List Manager as described there
To do this, first add a link to it, as shown in the screenshot below. Right-click on your project in your Visual Studio solution. Choose Add> Link .... Go to "COM" and find the entry "Network List 1.0 Library" using the search field.

This will create an Interop DLL for this COM interface in your binary output folder. This DLL is called Interop.NETWORKLIST.dll.
In your Solution Explorer, you can right-click on the NETWORKLIST link you just added and select โView in Object Explorerโ to check the interfaces available to you.

Here you can implement the Network Manager class, as shown below, to subscribe to connection change events.
using System; using System.Runtime.InteropServices.ComTypes; using System.Diagnostics; using NETWORKLIST; namespace SharpDisplayManager { public class NetworkManager: INetworkListManagerEvents, IDisposable { public delegate void OnConnectivityChangedDelegate(NetworkManager aNetworkManager, NLM_CONNECTIVITY aConnectivity); public event OnConnectivityChangedDelegate OnConnectivityChanged; private int iCookie = 0; private IConnectionPoint iConnectionPoint; private INetworkListManager iNetworkListManager; public NetworkManager() { iNetworkListManager = new NetworkListManager(); ConnectToNetworkListManagerEvents(); } public void Dispose() {
You can create your network manager as follows:
iNetworkManager = new NetworkManager(); iNetworkManager.OnConnectivityChanged += OnConnectivityChanged;
After receiving connection change events, you can check the IsConnectedToInternet and IsConnected attributes, as shown below:
public void OnConnectivityChanged(NetworkManager aNetwork, NLM_CONNECTIVITY newConnectivity) { //Update network status UpdateNetworkStatus(); } /// <summary> /// Update our Network Status /// </summary> private void UpdateNetworkStatus() { //TODO: Test the following functions to get network and Internet status //iNetworkManager.NetworkListManager.IsConnectedToInternet //iNetworkManager.NetworkListManager.IsConnected }
Here is a related question: INetworkConnectionEvents Supports what?