Buongiorno, devo pingare due dispositivi per controllarne la connessione.
Questo è il mio ciclo, il quale è messo all'interno di un Timer che esegue un Tick ogni 1000ms.
Il Timeout per il ping è impostato a 500ms
codice:
Private Async Sub doPing(ipHost As String, timeout As Integer, Optional tentativi As Integer = 1)
Dim totalPingsToTry As Integer = tentativi
Dim successCount As Integer
Using myPinger As New Ping
For counter As Integer = 1 To totalPingsToTry
Try
Dim myReply As PingReply = Await myPinger.SendPingAsync(ipHost, timeout)
If myReply.Status = IPStatus.Success Then
successCount += 1
End If
Catch ex As Exception
'Ping Failed
End Try
Next
End Using
If successCount / totalPingsToTry >= 0.7 Then
If disconnesso = True Then
riconnetti()
disconnesso = False
End If
Else
disconnesso = True
registraEvento("DISPOSITIVO NON CONNESSO", 0)
End If
End Sub
Il problema è che spesso, una volta ogni 10 minuti almeno, mi segnala connessione caduta, quando in realtà è presente.
Ho provato anche a controllare continuamente con ping -t con il prompt ed effettivamente col prompt non salta un colpo, mentre con VB.NET salta spesso.
Avete idee su come poter risolvere?