WlanClient无法更新/无法关闭WlanClient [英] WlanClient not updating/Not able to close WlanClient

查看:289
本文介绍了WlanClient无法更新/无法关闭WlanClient的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个后台工作程序,以获取所有可用WLAN网络的最新RSSI和链接质量.但是,如果在此后台工作程序中初始化WlanClient,则会收到此错误消息.

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.

试图建立到网络服务器的会话,但是已经建立了太多与该服务器vb.net的会话

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

但是,如果我创建一个公共类WlanClient,它不会更新RSSI和链接质量值,因为会话保持打开状态且未关闭.不确定如何关闭会话.但是,这是我用作后台工作人员的代码.

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

请让我知道如何在需要时关闭客户端或处置本地声明的WlanClient.

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

推荐答案

通过

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.

这篇关于WlanClient无法更新/无法关闭WlanClient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆