title: index out of range exception when using tasks
body: <p>I am getting "Index out of Range" exception when I am using the Async tasks on an array list. I checked all over stackoverflow and try different ways but none of them is working. Maybe I am missing something... Can someone please suggest.</p>
  
  <pre><code>        Task[] dataTasks = (from eachRow in ppcRowsCollection.Rows
                              select CreateDataRows(eachRow, subcTableArray, rowsArrayWithDefaultAndCommonValues)).ToArray();
  
  private async Task&lt;DataRow[]&gt; CreateDataRows(PpcRow givenPpcRow, DataTable[] subcTableArray, DataRow[] rowsArrayWithDefaultAndCommonValues)
  {
      return await Task.Run(() =&gt;
      {
          DataTable[] subcTableArrayLocal = subcTableArray;
          DataRow[] defaultRowsArray = GetrowsArrayWithDefaultAndCommonValues(ref subcTableArrayLocal, ref rowsArrayWithDefaultAndCommonValues);
          SetOtherThanCommonColumnValues(ref defaultRowsArray, givenPpcRow);
          return defaultRowsArray;
      }
      ).ConfigureAwait(false);
  }
  
  private DataRow[] GetrowsArrayWithDefaultAndCommonValues(ref DataTable[] subcTableArray, ref DataRow[] rowsArrayWithDefaultAndCommonValues)
  {
      DataRow[] defaultRowsArray = subcTableArray.Select(x =&gt; x.NewRow()).ToArray(); //This is where I am getting EXCEPTION
  
      DataRow[] defaultRowsArrayCopy = defaultRowsArray;
  
      foreach (DataRow row in defaultRowsArrayCopy)
      {
          row.ItemArray = rowsArrayWithDefaultAndCommonValues
                              .Where(x =&gt; x.Table.TableName == row.Table.TableName)
                              .First()
                              .ItemArray;
      }
      return defaultRowsArrayCopy;
  }
  </code></pre>
  
  <p>Stack Trace:</p>
  
  <blockquote>
    <p>at System.ThrowHelper.ThrowArgumentOutOfRangeException()    at
    System.Collections.Generic.List<code>1.get_Item(Int32 index)    at
    System.Data.RecordManager.NewRecordBase()    at
    System.Data.DataTable.NewRecord(Int32 sourceRecord)    at
    System.Data.DataTable.NewRow(Int32 record)    at
    System.Data.DataTable.NewRow()    at
    PedWebService.&lt;GetrowsArrayWithDefaultAndCommonValues&gt;b__21(DataTable
    x) in c:\Work\src\PedWebService.cs:line 2913    at
    System.Linq.Enumerable.WhereSelectArrayIterator</code>2.MoveNext()    at
    System.Linq.Buffer<code>1..ctor(IEnumerable</code>1 source)    at
    System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)    at
    PedWebService.GetrowsArrayWithDefaultAndCommonValues(DataTable[]&amp;
    subcTableArray, DataRow[]&amp; rowsArrayWithDefaultAndCommonValues) in
    c:\Work\src\PedWebService.cs:line 2913</p>
  </blockquote>