WlanClient not updating/Not able to close WlanClient

你说的曾经没有我的故事 提交于 2019-12-12 03:35:21

问题


I am trying to create a background worker for getting the latest RSSI and link quality for all the available WLAN networks. However, if I initialise the WlanClient inside this background worker, I get this error message.

An attempt was made to establish a session to a network server, but there are already too many sessions established to that server vb.net

However, if I create a public class WlanClient, it does not update the RSSI and link quality values as the session is kept open and is not closed. Not sure how to close the session. However, here is the code that I use as the background worker.

Private Sub Application_Idle(ByVal sender As Object, ByVal e As EventArgs)
    Try
        'Dim wlan As New WlanClient()
        'For Each wlanIface As WlanClient.WlanInterface In wlan.Interfaces
        For Each wlanIface As WlanClient.WlanInterface In WiFi.client.Interfaces
            Dim wlanBssEntries As Wlan.WlanBssEntry() = wlanIface.GetNetworkBssList()

            For Each network As Wlan.WlanBssEntry In wlanBssEntries
                Dim rss As Integer = network.rssi
                Dim macAddr As Byte() = network.dot11Bssid
                tMac = ""
                For i As Integer = 0 To macAddr.Length - 1
                    If tMac = "" Then
                        tMac += macAddr(i).ToString("x2").PadLeft(2, "0"c).ToUpper()
                    Else
                        tMac += ":" & macAddr(i).ToString("x2").PadLeft(2, "0"c).ToUpper()
                    End If
                Next
                Dim ssid As String = Encoding.ASCII.GetString(network.dot11Ssid.SSID, 0, CInt(network.dot11Ssid.SSIDLength))

                Dim available As Integer = 0
                Dim rowindex As Integer = -1
                For Each row As DataGridViewRow In DataGridView1.Rows
                    If row.Cells(0).Value.ToString().Equals(ssid) AndAlso row.Cells(1).Value.ToString().Equals(tMac) Then
                        available = 1
                        rowindex = row.Index
                        Exit For
                    End If
                Next
                If available = 0 Then
                    If Me.IsDisposed = True Then
                        Exit Sub
                    End If
                    DataGridView1.Rows.Add(ssid, tMac, network.dot11BssPhyType, rss, network.linkQuality)
                Else
                    If DataGridView1.Rows(rowindex).Cells(3).Value <> rss Or DataGridView1.Rows(rowindex).Cells(4).Value <> network.linkQuality Then
                        DataGridView1.Rows(rowindex).Cells(3).Value = rss
                        DataGridView1.Rows(rowindex).Cells(4).Value = network.linkQuality
                    End If
                End If
            Next
        Next
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
    Application.DoEvents()
    Thread.Sleep(100)
End Sub

Public Class WiFi
    Public Shared client As New WlanClient()
End Class

Kindly let me know on how to close the client whenever required or dispose a locally declared WlanClient.


回答1:


Found an answer via How do i reset the system cache of WLAN info? Adding wlanIface.Scan() after the first For loop solved the issue. Now the scan is picking up new data.



来源:https://stackoverflow.com/questions/42865204/wlanclient-not-updating-not-able-to-close-wlanclient

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!