مساعدة التحقق من الاتصال بالانترنت - dubai.eig - 18-05-17
اهلا بكم
يسعد الله اوقاتكم جميعا
عندي استفسار بخصوص كود التحقق من الانترنت
انا الكود اللي عندي هذا
كود :
If Computer.Network.IsAvailable Then
Try
If Computer.Network.Ping("www.Google.com") Then
MsgBox("Computer is connected")
Else
'MsgBox("Computer is not connected to the internet !!!")
End If
Catch
End Try
Else
'MsgBox("Computer is not connected to the internet !!!")
End If
هو شغال تمام
المشكله التي اواجهها
اني اقوم بالبحث في ملف xml موجود في احد المواقع
وفي حالت ضعف الانترنت يعلق البرنامج حتى يقوم بسحب المعلومات
وهذا الكود
كود :
Dim url As String = String.Format("https://www.hamqth.com/xml.php?id={0}&callsign={1} &prg=BKLOG", Label17.Text, calls.Text)
Dim document As XmlReader = New XmlTextReader(url)
'loop through the xml file
While (document.Read())
Dim type = document.NodeType
'if node type was element
If (type = XmlNodeType.Element) Then
'if the loop found a <FirstName> tag
If (document.Name = "adr_name") Then
Lfullname.Text = document.ReadInnerXml
End If
If (document.Name = "us_state") Then
state.Text = document.ReadInnerXml
End If
'if the loop found a <FirstName> tag
If (document.Name = "qth") Then
qth.Text = document.ReadInnerXml
End If
'if the loop found a <FirstName> tag
If (document.Name = "grid") Then
WORKinfo.GRIDSQUARE.Text = document.ReadInnerXml
End If
'if the loop found a <FirstName> tag
If (document.Name = "qsl_via") Then
WORKinfo.Lqslmgr.Text = document.ReadInnerXml
End If
'if the loop found a <FirstName> tag
If (document.Name = "latitude") Then
WORKinfo.LAT.Text = document.ReadInnerXml
End If
'if the loop found a <FirstName> tag
If (document.Name = "longitude") Then
WORKinfo.LON.Text = document.ReadInnerXml
End If
End If
End While
End If
الان السؤال هل في طريقة في حالت ضغف النت ما يقوم بسحب الداتا
بارك الله فيكم وشكرا
RE: مساعدة التحقق من الاتصال بالانترنت - alma2 - 18-05-17
كود :
Imports System.Xml
Public Class Form1
Dim WithEvents BackgroundWorker1 As New System.ComponentModel.BackgroundWorker
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Button1.Enabled = False
Button2.Enabled = True
If Not Me.BackgroundWorker1.IsBusy Then Me.BackgroundWorker1.RunWorkerAsync()
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
If Me.BackgroundWorker1.IsBusy Then Me.BackgroundWorker1.CancelAsync()
Button1.Enabled = True
Button2.Enabled = False
End Sub
Private Sub BackgroundWorker1_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
BackgroundWorker1.WorkerSupportsCancellation = True
Control.CheckForIllegalCrossThreadCalls = False
Dim url As String = String.Format("https://www.hamqth.com/xml.php?id={0}&callsign={1} &prg=BKLOG", Label17.Text, calls.Text)
Dim document As New XmlTextReader(url)
'loop through the xml file
While (document.Read())
If Me.BackgroundWorker1.CancellationPending Then Exit Sub
Dim type = document.NodeType
'if node type was element
If (type = XmlNodeType.Element) Then
'if the loop found a <FirstName> tag
If (document.Name = "adr_name") Then
Lfullname.Text = document.ReadInnerXml
End If
If (document.Name = "us_state") Then
state.Text = document.ReadInnerXml
End If
'if the loop found a <FirstName> tag
If (document.Name = "qth") Then
qth.Text = document.ReadInnerXml
End If
'if the loop found a <FirstName> tag
If (document.Name = "grid") Then
WORKinfo.GRIDSQUARE.Text = document.ReadInnerXml
End If
'if the loop found a <FirstName> tag
If (document.Name = "qsl_via") Then
WORKinfo.Lqslmgr.Text = document.ReadInnerXml
End If
'if the loop found a <FirstName> tag
If (document.Name = "latitude") Then
WORKinfo.LAT.Text = document.ReadInnerXml
End If
'if the loop found a <FirstName> tag
If (document.Name = "longitude") Then
WORKinfo.LON.Text = document.ReadInnerXml
End If
End If
End While
End Sub
End Class
RE: مساعدة التحقق من الاتصال بالانترنت - dubai.eig - 18-05-17
شكرا ساجرب الان ان شاءالله
RE: مساعدة التحقق من الاتصال بالانترنت - dubai.eig - 19-05-17
(18-05-17, 04:09 PM)alma2 كتب :
كود :
Imports System.Xml
Public Class Form1
Dim WithEvents BackgroundWorker1 As New System.ComponentModel.BackgroundWorker
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Button1.Enabled = False
Button2.Enabled = True
If Not Me.BackgroundWorker1.IsBusy Then Me.BackgroundWorker1.RunWorkerAsync()
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
If Me.BackgroundWorker1.IsBusy Then Me.BackgroundWorker1.CancelAsync()
Button1.Enabled = True
Button2.Enabled = False
End Sub
Private Sub BackgroundWorker1_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
BackgroundWorker1.WorkerSupportsCancellation = True
Control.CheckForIllegalCrossThreadCalls = False
Dim url As String = String.Format("https://www.hamqth.com/xml.php?id={0}&callsign={1} &prg=BKLOG", Label17.Text, calls.Text)
Dim document As New XmlTextReader(url)
'loop through the xml file
While (document.Read())
If Me.BackgroundWorker1.CancellationPending Then Exit Sub
Dim type = document.NodeType
'if node type was element
If (type = XmlNodeType.Element) Then
'if the loop found a <FirstName> tag
If (document.Name = "adr_name") Then
Lfullname.Text = document.ReadInnerXml
End If
If (document.Name = "us_state") Then
state.Text = document.ReadInnerXml
End If
'if the loop found a <FirstName> tag
If (document.Name = "qth") Then
qth.Text = document.ReadInnerXml
End If
'if the loop found a <FirstName> tag
If (document.Name = "grid") Then
WORKinfo.GRIDSQUARE.Text = document.ReadInnerXml
End If
'if the loop found a <FirstName> tag
If (document.Name = "qsl_via") Then
WORKinfo.Lqslmgr.Text = document.ReadInnerXml
End If
'if the loop found a <FirstName> tag
If (document.Name = "latitude") Then
WORKinfo.LAT.Text = document.ReadInnerXml
End If
'if the loop found a <FirstName> tag
If (document.Name = "longitude") Then
WORKinfo.LON.Text = document.ReadInnerXml
End If
End If
End While
End Sub
End Class
شكرا لك فعلا هذا الكود اللي كنت احتاجه
شكرا
|