i have this code to ping a list of over 400 switches , the program works fine but for some reason the first time i ping all the switches alot of the attempts time-out(even tho they shouldnt) which makes the program alot slower , if i click ping again less of the attempts time-out(and as a result the program runs faster) and if i click it a third time i usually get a completely accurate result with all the switches pinging back "success" (except for a few which i know for a fact are down anyway) any ideas why this is ??
Code:Public Class SwitchMonitor Dim Ping As Net.NetworkInformation.Ping Dim pReply As Net.NetworkInformation.PingReply Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer Dim ds As New DataSet Dim da As OleDb.OleDbDataAdapter Dim sql As String Dim con As New OleDb.OleDbConnection Label1.Visible = True Label2.Visible = True Label3.Visible = True Label4.Visible = True Label5.Visible = True con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\mhorgan\Desktop\Network Map.mdb" con.Open() sql = "SELECT * FROM tblSwitch" da = New OleDb.OleDbDataAdapter(sql, con) da.Fill(ds, "monitor") Dim cb As New OleDb.OleDbCommandBuilder(da) Ping = New Net.NetworkInformation.Ping Dim dgvr As DataGridViewRow ProgressBar1.Minimum = 0 'sets minimum value of progress bar ProgressBar1.Maximum = ds.Tables("monitor").Rows.Count - 1 'sets maximum value of progress bar For i = 0 To ds.Tables("monitor").Rows.Count - 1 Application.DoEvents() ' Set up the progress bar's properties ProgressBar1.Value = i dgvr = New DataGridViewRow 'Creates a new row DataGridView1.Rows.Add(dgvr) 'Add the row Try pReply = Ping.Send(ds.Tables("monitor").Rows(i).Item(5)) 'Sends the ping to the current item DataGridView1.Rows.Item(i).Cells(0).Value = ds.Tables("monitor").Rows(i).Item(1) 'read in switch name from column 2 DataGridView1.Rows.Item(i).Cells(1).Value = ds.Tables("monitor").Rows(i).Item(5) 'Updates the value of the new Item DataGridView1.Rows.Item(i).Cells(2).Value = pReply.Status 'The value of the status returned DataGridView1.Rows.Item(i).Cells(3).Value = Now.ToString() 'show the last time checked with Now.ToString() method If pReply.Status <> Net.NetworkInformation.IPStatus.Success Then 'Sets the color of the cell DataGridView1.Rows.Item(i).Cells(2).Style.BackColor = Color.Red Else DataGridView1.Rows.Item(i).Cells(2).Style.BackColor = Color.Green End If ds.Tables("monitor").Rows(i).Item(6) = pReply.Status 'Write in the original datatable ds.Tables("monitor").Rows(i).Item(7) = Now.ToString() 'added code for date/time da.Update(ds, "monitor") 'Updates the database Catch ex As Exception MessageBox.Show(ex.ToString()) End Try Next End Sub Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click Dim con As New OleDb.OleDbConnection con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\mhorgan\Desktop\Network Map.mdb" con.Close() End End Sub Private Sub SwitchMonitor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub End Class




Reply With Quote
