title: For Loop result in Overflow with Task.Run or Task.Start
body: <p>got a Problem, hope someone can help me out.</p>
  
  <p>i try to start 4 Task in an Loop but im getting an ArgumentOutOfRangeException:</p>
  
  <pre><code> for (int i = 0; i &lt; 4; i++)
       {
            //start task with current connection
            tasks[i] = Task&lt;byte[]&gt;.Run(() =&gt; GetData(i, plcPool[i]));
       }
  </code></pre>
  
  <p>The Loop gets an Overflow because i = 4</p>
  
  <p>if i start the Tasks without a Loop, they run without any Problems:</p>
  
  <pre><code>            tasks[0] = Task&lt;byte[]&gt;.Run(() =&gt; GetData(0, plcPool[0]));
              tasks[1] = Task&lt;byte[]&gt;.Run(() =&gt; GetData(1, plcPool[1]));
              tasks[2] = Task&lt;byte[]&gt;.Run(() =&gt; GetData(2, plcPool[2]));
              tasks[3] = Task&lt;byte[]&gt;.Run(() =&gt; GetData(3, plcPool[3]));
  </code></pre>
  
  <p>dont know why? The Tasks GetData from a Siemens PLC via Socket Connection. The PLC Supports up to 32 Connections. I receive 200 Bytes per Connection.</p>
  
  <pre><code> private byte[] GetData(int id, PLC plc)
      {
          switch (id)
          {
              case 0:
                  return plc.ReadBytes(DataType.DataBlock, 50, 0, 200);
              case 1:
                  return plc.ReadBytes(DataType.DataBlock, 50, 200, 200);
              case 2:
                  return plc.ReadBytes(DataType.DataBlock, 50, 500, 200);
              case 3:
                  return plc.ReadBytes(DataType.DataBlock, 50, 700, 200);
              case 4:
                  return plc.ReadBytes(DataType.DataBlock, 50, 900, 117);
              default:
                  return null;
          }
      }
  </code></pre>
  
  <p>any idea?</p>
  
  <p>Regards Sam</p>