Note that there are some explanatory texts on larger screens.

plurals
  1. POClosing WiFi connections using the Managed API
    text
    copied!<p>I'm writing a program using the <a href="http://managedwifi.codeplex.com/" rel="nofollow">Managed WiFi API</a>. Here's how I get all the networks in range:</p> <pre><code> void UpdateNetworks() { networks = new List&lt;Wlan.WlanAvailableNetwork&gt;(); WlanClient client = new WlanClient(); foreach(WlanClient.WlanInterface iface in client.Interfaces) { Wlan.WlanAvailableNetwork[] nets = iface.GetAvailableNetworkList(0); foreach(Wlan.WlanAvailableNetwork net in nets) networks.Add(net); } } </code></pre> <p>The problem is that after 18 calls to this method I can no longer connect:</p> <blockquote> <p>(0x80004005): An attempt was made to establish a session to a network server, but there are already too many sessions established to that server.</p> </blockquote> <p>Here's the constructor that's throwing the exception:</p> <pre><code> public WlanClient() { Wlan.ThrowIfError( Wlan.WlanOpenHandle(Wlan.WLAN_CLIENT_VERSION_XP_SP2, IntPtr.Zero, out negotiatedVersion, out clientHandle)); try { Wlan.WlanNotificationSource prevSrc; wlanNotificationCallback = new Wlan.WlanNotificationCallbackDelegate(OnWlanNotification); Wlan.ThrowIfError( Wlan.WlanRegisterNotification(clientHandle, Wlan.WlanNotificationSource.All, false, wlanNotificationCallback, IntPtr.Zero, IntPtr.Zero, out prevSrc)); } catch { Wlan.WlanCloseHandle(clientHandle, IntPtr.Zero); throw; } } </code></pre> <p>I believe this is because the client never closes the connections it opens. How do I close them explicitly? There's handle closing in the <code>catch</code> block, but it requires access to the client's private parts.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload