title: C# WCF service out of bounds array index
body: <p>So I have a service that instantiates an array of objects and then starts a new process for those objects. I wait for the instantiation and the new processes to start before getting some data from the objects in a another thread. For some reason I am getting out bounds index when trying to read the data. It seems to be trying to access an index that is 1 larger than what i define (trying to access Os[4] when the last index is Os[3]), hence being out of bounds? what could be causing this?</p>
  
  <pre><code>        lock (initlock)
          {
              for (threadNum = 0; threadNum &lt; 4; threadNum++)
              {
                  Os[threadNum] = new myO();
                  Thread TOs[threadNum] = new Thread(new ThreadStart(Os[threadNum].ProcessData));
                  TOs[threadNum].Start();
              }
          }
  
          lock (initlock)
          {
              for (int i = 0; i &lt; 4; i++)
              {
                  Thread rd[i] = new Thread(new ThreadStart(() =&gt; Os[i].GetData());
                  rd[i].Start();
              }
          }
  </code></pre>