الطريقة الصحيحة للتأكد من حالة الإتصال بالإنترنت
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TestCon() = True Then
MsgBox("Connect", MessageBoxButtons.OK + MsgBoxStyle.Information)
Else
MsgBox("Not Connect", MessageBoxButtons.OK + MsgBoxStyle.Information)
End If
End Sub
Public Function TestCon() As Boolean
Dim Objurl As New System.Uri("https://www.google.com/")
Dim Objwebreg As System.Net.WebRequest
Objwebreg = System.Net.WebRequest.Create(Objurl)
Dim Objresp As System.Net.WebResponse
Try
Objresp = Objwebreg.GetResponse
Objresp.Close()
Objresp = Nothing
Return True
Catch exp As Exception
Objresp = Nothing
Objwebreg = Nothing
Return False
End Try
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TestCon() = True Then
MsgBox("Connect", MessageBoxButtons.OK + MsgBoxStyle.Information)
Else
MsgBox("Not Connect", MessageBoxButtons.OK + MsgBoxStyle.Information)
End If
End Sub
Public Function TestCon() As Boolean
Dim Objurl As New System.Uri("https://www.google.com/")
Dim Objwebreg As System.Net.WebRequest
Objwebreg = System.Net.WebRequest.Create(Objurl)
Dim Objresp As System.Net.WebResponse
Try
Objresp = Objwebreg.GetResponse
Objresp.Close()
Objresp = Nothing
Return True
Catch exp As Exception
Objresp = Nothing
Objwebreg = Nothing
Return False
End Try
End Function