2014-05-19 6 views
1

J'essaie d'utiliser cette API; Cependant, je ne peux pas déclencher les événements. Donc, cela utilise Network List 1.0 Type Library com.INetworkConnectionEvents Prend en charge quoi?

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

donc j'ai mis une pause sur tous les événements. et vs n'éclate jamais.

Répondre

2

vous avez défini toutes les fonctions de rappel nécessaires, c'est génial. Mais vous devez vous inscrire à ces événements en appelant la méthode d'interface réseau "advis" pour les réseaux d'intérêt.

Voici un exemple de code pour que:

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

S'il vous plaît ne pas oublier le "unadvise" qui prend le cookie entier (s) comme paramètre.

+0

doit être marqué comme réponse –