تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
الطريقة الصحيحة للتأكد من حالة الإتصال بالإنترنت
#1
الطريقة الصحيحة للتأكد من حالة الإتصال بالإنترنت

    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
الرد }}}
تم الشكر بواسطة:



التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم