INetworkConnectionEvents Supports What?

I am trying to use this API; however, I cannot get events to shoot. So this is using the List List List List 1.0 library.

Here is my code:

public class AvailibleWLan : INetworkListManagerEvents, INetworkEvents, INetworkConnectionEvents { public NETWORKLIST.INetworkListManager NewWorkList {get;set;} public List<WirelessNetwork> Connections { get; set; } public AvailibleWLan() { Connections = new List<WirelessNetwork>(); NewWorkList = new NETWORKLIST.NetworkListManager(); foreach (NETWORKLIST.INetwork Network in NewWorkList.GetNetworks(NETWORKLIST.NLM_ENUM_NETWORK.NLM_ENUM_NETWORK_ALL)) { String Name = Network.GetName(); var Connectivity = Network.GetConnectivity(); var Description = Network.GetDescription(); } } //public event NetworkPropertyChanged NetworkConnectivityChanged; public WirelessNetwork Network { get; set; } void INetworkListManagerEvents.ConnectivityChanged(NLM_CONNECTIVITY newConnectivity) { throw new NotImplementedException(); } void INetworkConnectionEvents.NetworkConnectionConnectivityChanged(Guid connectionId, NLM_CONNECTIVITY newConnectivity) { throw new NotImplementedException(); } void INetworkConnectionEvents.NetworkConnectionPropertyChanged(Guid connectionId, NLM_CONNECTION_PROPERTY_CHANGE Flags) { throw new NotImplementedException(); } void INetworkEvents.NetworkAdded(Guid networkId) { throw new NotImplementedException(); } void INetworkEvents.NetworkConnectivityChanged(Guid networkId, NLM_CONNECTIVITY newConnectivity) { throw new NotImplementedException(); } void INetworkEvents.NetworkDeleted(Guid networkId) { throw new NotImplementedException(); } void INetworkEvents.NetworkPropertyChanged(Guid networkId, NLM_NETWORK_PROPERTY_CHANGE Flags) { throw new NotImplementedException(); } } 

So, I put a break on all events. and vs never flashes.

+1
source share
1 answer

You have defined all the necessary callback functions, which is great. But you must register for these events by invoking the β€œadvise” network interface method for networks of interest.

Here is a sample code for this:

 namespace NetworkListSample { class TestNetworkEvents : INetworkListManagerEvents, INetworkConnectionEvents { private INetworkListManager m_nlm = new NetworkListManager(); private static Guid s_INetworkListManagerEventsGuid = typeof(INetworkListManagerEvents).GUID; private static Guid s_INetworkConnectionEventsGuid = typeof(INetworkConnectionEvents).GUID; public void RegisterForEvents() { // Here it will only register for events of a network which is connected, // if you wish to register for events of disconnected networks // use a different NLM_ENUM_NETWORK enum value IEnumNetworks Networks = m_nlm.GetNetworks(NLM_ENUM_NETWORK.NLM_ENUM_NETWORK_CONNECTED); foreach (INetwork item in Networks) { IConnectionPoint cp = null; IConnectionPointContainer icpc = (IConnectionPointContainer)m_nlm; int cookie = -1; Guid tempGuid = s_INetworkListManagerEventsGuid; icpc.FindConnectionPoint(ref tempGuid, out cp); cp.Advise(this, out cookie); } } public void ConnectivityChanged(NLM_CONNECTIVITY newConnectivity) { throw new NotImplementedException(); } public void NetworkConnectionConnectivityChanged(Guid connectionId, NLM_CONNECTIVITY newConnectivity) { throw new NotImplementedException(); } public void NetworkConnectionPropertyChanged(Guid connectionId, NLM_CONNECTION_PROPERTY_CHANGE Flags) { throw new NotImplementedException(); } } } 

Please do not forget "unadvise", which accepts integer cookies as a parameter.

+2
source

Source: https://habr.com/ru/post/1379872/


All Articles