Exemplo n.º 1
0
        internal void OnWlanConnection(WlanNotificationData notifyData, WlanConnectionNotificationData connNotifyData)
        {
            if (WlanConnectionNotification != null)
            {
                WlanConnectionNotification(notifyData, connNotifyData);
            }

            if (queueEvents)
            {
                WlanConnectionNotificationEventData queuedEvent = new WlanConnectionNotificationEventData();
                queuedEvent.notifyData     = notifyData;
                queuedEvent.connNotifyData = connNotifyData;
                EnqueueEvent(queuedEvent);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Connects (associates) to the specified wireless network, returning either on a success to connect
 /// or a failure.
 /// </summary>
 /// <param name="connectionMode"></param>
 /// <param name="bssType"></param>
 /// <param name="profile"></param>
 /// <param name="connectTimeout"></param>
 /// <returns></returns>
 public bool ConnectSynchronously(WlanConnectionMode connectionMode, Dot11BssType bssType, string profile, int connectTimeout)
 {
     queueEvents = true; // NOTE: This can cause side effects, other places in the application might not get events properly.
     try
     {
         Connect(connectionMode, bssType, profile);
         while (queueEvents && eventQueueFilled.WaitOne(connectTimeout, true))
         {
             lock (eventQueue)
             {
                 while (eventQueue.Count != 0)
                 {
                     object e = eventQueue.Dequeue();
                     if (e is WlanConnectionNotificationEventData)
                     {
                         WlanConnectionNotificationEventData wlanConnectionData = (WlanConnectionNotificationEventData)e;
                         // Check if the conditions are good to indicate either success or failure.
                         if (wlanConnectionData.notifyData.notificationSource == WlanNotificationSource.MSM)
                         {
                             switch ((WlanNotificationCodeMsm)wlanConnectionData.notifyData.notificationCode)
                             {
                             case WlanNotificationCodeMsm.Connected:
                                 if (wlanConnectionData.connNotifyData.profileName == profile)
                                 {
                                     return(true);
                                 }
                                 break;
                             }
                         }
                         break;
                     }
                 }
             }
         }
     }
     finally
     {
         queueEvents = false;
         eventQueue.Clear();
     }
     return(false); // timeout expired and no "connection complete"
 }