INetworkConnectionEvents支持什么



我正在尝试使用这个API;然而,我无法让事件触发。所以这是使用网络列表1.0类型库。com.

下面是我的代码:
 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();
    }
}

所以我把所有的事件都中断了。而vs永远不会爆发。

您定义了所有必要的回调函数,这很好。但是,您必须为感兴趣的网络调用网络接口方法"advise"来注册这些事件。

下面是一个示例代码:

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();
        }
    }
}

请不要忘记"unadvise",它接受整型cookie作为参数

相关内容

  • 没有找到相关文章

最新更新