title: vb.net System.ArgumentOutOfRangeException When Trying to ping
body: <p>been trying to follow this guide on how to make picture boxes change colour depending on if the ping has been successful or not. I have some test ip's in a CSV file that the program imports</p>
  <p>but I keep getting a exception error. I have 3 picture boxes on the page currently defined from picturebox2 - 4</p>
  <p><a href="https://i.stack.imgur.com/zKYxN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zKYxN.png" alt="enter image description here" /></a></p>
  <p>the code for the whole page is below, any suggestions or fixes would be greatly appreciated</p>
  <pre><code>Imports System.Net
  Imports System.Net.NetworkInformation
  Imports System.Threading
  Imports System.IO
  Imports System.Timers
  
  
  Public Class Central
      Dim pingTable As DataTable = New DataTable()
      Dim ipAddress As List(Of String) = New List(Of String)
      Dim pictureBoxList As List(Of PictureBox) = New List(Of PictureBox)
      Dim timer As Timers.Timer
  
      Public Sub New()
  
          ' This call is required by the designer.
          InitializeComponent()
  
          ' Add any initialization after the InitializeComponent() call.
          timer = New Timers.Timer
          timer.Interval = 20000
          timer.Enabled = True
          AddHandler timer.Elapsed, AddressOf OnElapsedTime
  
      End Sub
      Private Sub OnElapsedTime(ByVal sender As Object, ByVal e As ElapsedEventArgs)
          BackgroundWorker1.RunWorkerAsync()
      End Sub
  
      Private Sub FillPingTable()
          pingTable.Columns.Add(&quot;ip&quot;, GetType(String))
          pingTable.Columns.Add(&quot;picturebox&quot;, GetType(String))
          pingTable.Rows.Add()
          For i As Integer = 0 To ipAddress.Count - 1
              pingTable.Rows.Add(ipAddress(i), pictureBoxList(i))
          Next
      End Sub
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
          Hide()
          Scot.Show()
      End Sub
  
      Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
          Hide()
          Home.Show()
      End Sub
  
      Private Sub central_Load(sender As Object, e As EventArgs) Handles MyBase.Load
          Using reader = New StreamReader(&quot;A:\IpAddress.csv&quot;)
              While Not reader.EndOfStream
                  Dim line = reader.ReadLine
                  Dim values = line.Split(ChrW(10))
                  ipAddress.Add(values(0))
              End While
  
              For i As Integer = 1 To 2
                  pictureBoxList.Add(CType(Controls.Find(&quot;PictureBox&quot; &amp; i, True)(0), PictureBox))
                  FillPingTable()
                  BackgroundWorker1.RunWorkerAsync()
  
              Next
          End Using
      End Sub
  
      Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
          Thread.Sleep(500)
          Parallel.For(0, ipAddress.Count(), Sub(i, loopState)
                                                 Dim ping As New Ping()
                                                 Dim pingReply As PingReply = ping.Send(ipAddress(i).ToString())
                                                 Me.BeginInvoke(CType(Sub()
                                                                          pictureBoxList(i).SizeMode = PictureBoxSizeMode.Zoom
                                                                          pictureBoxList(i).BackColor = If(pingReply.Status = IPStatus.Success, Color.Green, Color.Red)
                                                                      End Sub, Action))
                                             End Sub)
      End Sub
  End Class
  </code></pre>