Public Class Form1
Private WithEvents bgw As New System.ComponentModel.BackgroundWorker
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Button1.Enabled = False
Dim arrComputers() As String = TextBox5.Text.Split(Environment.NewLine.ToCharArray, StringSplitOptions.RemoveEmptyEntries)
Dim listToPing As New List(Of String)
For Each strComputer As String In arrComputers
listToPing.Add(strComputer.Trim)
Next
bgw.RunWorkerAsync(listToPing)
End Sub
Private Sub bgw_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bgw.DoWork
Dim listToPing As List(Of String) = CType(e.Argument, List(Of String))
Dim pingURL As String = ""
Dim blogURL As String = "http://www.jeremywadsworth.com"
Dim blogName As String = "Jeremy Wadsworth"
For j As Integer = 0 To listToPing.Count - 1
Try
pingURL = listToPing.Item(j).ToString
Dim technoratiPing As HttpWebRequest = CType(WebRequest.Create(pingURL), HttpWebRequest)
technoratiPing.Method = "POST"
technoratiPing.ContentType = "text/xml"
Dim streamPingRequest As Stream = CType(technoratiPing.GetRequestStream, Stream)
Dim xmlPing As XmlTextWriter = New XmlTextWriter(streamPingRequest, System.Text.Encoding.UTF8)
xmlPing.WriteStartDocument()
xmlPing.WriteStartElement("methodCall")
xmlPing.WriteElementString("methodName", "weblogUpdates.ping")
xmlPing.WriteStartElement("params")
xmlPing.WriteStartElement("param")
xmlPing.WriteElementString("value", blogName)
xmlPing.WriteEndElement()
xmlPing.WriteStartElement("param")
xmlPing.WriteElementString("value", blogURL)
xmlPing.WriteEndElement()
xmlPing.WriteEndElement()
xmlPing.WriteEndElement()
xmlPing.Close()
Dim technoratiPingResponse As HttpWebResponse = CType(technoratiPing.GetResponse, HttpWebResponse)
Dim streamPingResponse As StreamReader = New StreamReader(technoratiPingResponse.GetResponseStream)
Dim strResult As String = streamPingResponse.ReadToEnd
streamPingResponse.Close()
technoratiPingResponse.Close()
Catch ex As Exception
'Add code here to flag a service as broken
End Try
Next
End Sub
Private Sub bgw_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgw.RunWorkerCompleted
MessageBox.Show("Done", "Ping Completed", MessageBoxButtons.OK, MessageBoxIcon.Information)
Button1.Enabled = True
End Sub
End Class
|