WlanClient 无法 updating/Not 关闭 WlanClient
WlanClient not updating/Not able to close WlanClient
我正在尝试创建一个后台工作程序来为所有可用的 WLAN 网络获取最新的 RSSI 和 link 质量。但是,如果我在此后台工作程序中初始化 WlanClient,则会收到此错误消息。
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
但是,如果我创建 public class WlanClient,它不会更新 RSSI 和 link 质量值,因为会话保持打开状态并且不会关闭。不确定如何关闭会话。但是,这是我用作后台工作人员的代码。
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。
通过 找到答案 在第一个 For
循环后添加 wlanIface.Scan()
解决了问题。现在扫描正在获取新数据。
我正在尝试创建一个后台工作程序来为所有可用的 WLAN 网络获取最新的 RSSI 和 link 质量。但是,如果我在此后台工作程序中初始化 WlanClient,则会收到此错误消息。
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
但是,如果我创建 public class WlanClient,它不会更新 RSSI 和 link 质量值,因为会话保持打开状态并且不会关闭。不确定如何关闭会话。但是,这是我用作后台工作人员的代码。
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。
通过 For
循环后添加 wlanIface.Scan()
解决了问题。现在扫描正在获取新数据。