Got "Index out of bounds" Error on List.Add() in c#
In order to prevent the issue, instead of List you may use ConcurrentQueue
or similar Concurrent collections in your parallel part. Once the parallel task is done, you can put it in the List<T>
.
For more information take a look at System.Collections.Concurrent namespace to find the suitable collection for your use case.