I need to implement an Endless loop for the below code. I want to be able to click a button to stop the execution of the below code. How can i create an endless loop that will continue to do the code until I click a stop button?
Code:
Private Sub cmdStartPing_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStartPing.Click
Dim serverlist, x As Integer
Dim servers As String
Dim response As New ListViewItem
serverlist = lstServers.Items.Count - 1
For x = 0 To serverlist
servers = lstServers.Items(x).Text
MultiPingSystem(servers)
If pingresults = "Success" Then
lstServers.Items(x).BackColor = Color.GreenYellow
lstServers.Items(x).SubItems.Add("Success")
lstServers.Refresh()
lstServers.Items(x).SubItems.Add(roundtriptime)
lstServers.Refresh()
Else
lstServers.Items(x).BackColor = Color.Red
lstServers.Items(x).SubItems.Add("No Reply")
lstServers.Refresh()
lstServers.Items(x).SubItems.Add("Timeout")
lstServers.Refresh()
lstServers.Items(x).SubItems.Add(currentdt)
lstServers.Refresh()
End If
Next
End Sub