Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid with Continues Asnychronous Ping not updating correctly

Status
Not open for further replies.

Shift838

IS-IT--Management
Jan 27, 2003
987
US
I have a Datagridview that has a list of servers, start command button and stop command button. Pressing the start button starts a continuous Asynchronous ping on all servers in the datagridview. The issue is that when a server goes down the datagridview stops updating for 5-10 seconds. I also have a context menu that comes up and allows me to delete a row if needed, but when the server times out my context menu does not come up and the app freezes until the timeout is registered. What am I doing wrong. The code is below:

Start ping:

Code:
Private Sub cmdStartPing_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStartPing.Click

        Dim rc, myic As Integer
        Dim sname As String
        'Dim preply As PingReply

        pinging = 1
        cmdStopPing.Select()
        rc = DGV1.RowCount - 1

        If rc > -1 Then

            bCancel = False

            Do Until bCancel = True

                For myic = 0 To rc

                    Application.DoEvents()

                    If bCancel Then
                        bCancel = True
                        DGV1.BackgroundColor = Color.White
                        MsgBox("Pinging Stopped")
                        Exit For

                    End If




                    Try
                        sname = DGV1.Item(0, myic).Value

                        PingHost(sname)

                        If pingresults = "Success" Then
                            DGV1.Rows(myic).Cells(1).Value = "Success"
                            DGV1.Rows(myic).Cells(2).Value = roundtriptime
                            DGV1.Rows(myic).DefaultCellStyle.BackColor = Color.YellowGreen
                            DGV1.Refresh()
                        Else
                            DGV1.Rows(myic).Cells(1).Value = "No Reply"
                            DGV1.Rows(myic).Cells(2).Value = "Timed Out"
                            DGV1.Rows(myic).Cells(3).Value = currentdt
                            DGV1.Rows(myic).DefaultCellStyle.BackColor = Color.Red
                            DGV1.Refresh()
                        End If

                    Catch ex As Exception
                        DGV1.Rows(myic).Cells(1).Value = "No Reply"
                        DGV1.Rows(myic).Cells(2).Value = "Timed Out"
                        DGV1.Rows(myic).Cells(3).Value = currentdt
                        DGV1.Rows(myic).DefaultCellStyle.BackColor = Color.Red
                        DGV1.Refresh()
                        

                    End Try


                Next

            Loop

        Else
            MsgBox("Please add at least one host to the datagrid to ping.")
        End If

    End Sub


Stop Ping:

Code:
Private Sub cmdStopPing_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStopPing.Click
        bCancel = True
        pinging = 0
    End Sub


Ping module:

Code:
Module AsyncPingHost
    'Function PingIPAdress(ByVal IPAdress As String)
    Function PingHost(ByVal host As String)
        Dim ping As Ping
        Dim preply As PingReply
        ping = New Ping
        
        Try
            preply = ping.Send(host)
            roundtriptime = preply.RoundtripTime
            If preply.Status = IPStatus.Success Then
                pingresults = "Success"
            Else
                pingresults = "Failed"

            End If
        Catch ex As Exception
            pingresults = ex.Message
        End Try


    End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top