I'm writing a .Net class library that's to connect to a specific Wif开发者_运维技巧i network whose name is known in advance, when the signal strength is above a certain threshold.
It all works beautifully, EXCEPT that peformance is a bit spotty. I have a polling thread that repeatedly calls WlanGetAvailableNetworks(). This loop performs well - WLanGetAvailableNetworks() typically takes only 10-20ms. HOWEVER, the signal strength attribute in the WLAN_AVAILALBLE_NETWORK structure seems to take a long time to update. I've seen it take up to 100 seconds to register an updated value when moving to an area with a known signal strength.
I've found cryptic references to the update interval, including this one, from a guy who's implemented a NETSH spawner: http://www.codeproject.com/KB/gadgets/WifiScanner.aspx?msg=3031431
But I haven't found anyone who's addressed this specific question: Is it possible to tweak the update interval for signal strength and other network parameters in the Native Wifi API?
Or, am I missing another helpful concept? (I'm a complete noob, regarding Wifi).
Possibly relevant environmental info: -- .Net 3.5 -- XP plus KB fix for WlanApi -- C# / VS 2008 (4.0 and VS2010 available)
thanks --
Carl
Oops. I missed this in the WLANAPI documentation: WlanScan()! Call that before WlanGetAvailableNetworks() to ensure that WlanGetAvailableNetworks() returns more or less current information. According to the doc (http://msdn.microsoft.com/en-us/library/ms706783(VS.85).aspx), WlanScan() completes immediately and starts an asynchronous scan.
Empirically, what seems to happen is that the next WlanGetAvailableNetworks() appears to stall until the scan completes (3.085 seconds, +/- 0.031 seconds, in my testing). So, as the doc indicates, you don't want to do this anywhere that will cripple performance. Also, three seconds is probably about the best possible temporal resolution for wifi signal checks, at least on XP (Vista and 7 versions of WLANAPI support single-network WlanScan(), which may complete more quickly).
Problem solved, more or less.
精彩评论