public void Start() { for (_currentIteration = 0; _currentIteration < ExecutionIterations; _currentIteration++) { if (!ExecuteInParallel) { foreach (var module in IterationModules) { _currentlyExecutingModule = module; module.Start(); } } else { Thread[] threads = new Thread[IterationModules.Length]; ConcurrentQueue <Exception> errorList = new ConcurrentQueue <Exception>(); for (int i = 0; i < threads.Length; i++) { var avoidSharingI = i; threads[i] = new Thread(() => { try { IterationModules[avoidSharingI].Start(); } catch (Exception e) { errorList.Enqueue(e); } }); threads[i].IsBackground = true; threads[i].Start(); } // after creating all of the threads wait until each one is complete before continuing for (int i = 0; i < threads.Length; i++) { threads[i].Join(); } if (errorList.Count > 0) { throw new AggregateException(errorList.ToArray()); } } } }