More consistent clock and clear support.
2 using System.Collections.Generic;
5 using System.Threading.Tasks;
6 using System.Net.NetworkInformation;
7 using System.Runtime.InteropServices;
8 using System.Runtime.InteropServices.ComTypes;
9 using System.Diagnostics;
12 namespace SharpDisplayManager
14 public class NetworkManager: INetworkListManagerEvents, IDisposable
16 public delegate void OnConnectivityChangedDelegate(NetworkManager aNetworkManager, NLM_CONNECTIVITY aConnectivity);
17 public event OnConnectivityChangedDelegate OnConnectivityChanged;
19 private int iCookie = 0;
20 private IConnectionPoint iConnectionPoint;
21 private INetworkListManager iNetworkListManager;
24 public NetworkManager()
26 iNetworkListManager = new NetworkListManager();
27 ConnectToNetworkListManagerEvents();
32 //Not sure why this is not working form here
33 //Possibly because something is doing automatically before we get there
34 //DisconnectFromNetworkListManagerEvents();
38 public INetworkListManager NetworkListManager
40 get { return iNetworkListManager; }
43 public void ConnectivityChanged(NLM_CONNECTIVITY newConnectivity)
46 OnConnectivityChanged(this, newConnectivity);
49 public void ConnectToNetworkListManagerEvents()
51 Debug.WriteLine("Subscribing to INetworkListManagerEvents");
52 IConnectionPointContainer icpc = (IConnectionPointContainer)iNetworkListManager;
53 //similar event subscription can be used for INetworkEvents and INetworkConnectionEvents
54 Guid tempGuid = typeof(INetworkListManagerEvents).GUID;
55 icpc.FindConnectionPoint(ref tempGuid, out iConnectionPoint);
56 iConnectionPoint.Advise(this, out iCookie);
60 public void DisconnectFromNetworkListManagerEvents()
62 Debug.WriteLine("Un-subscribing to INetworkListManagerEvents");
63 iConnectionPoint.Unadvise(iCookie);