No need to do all this silly goosery if you have Rx:
records.ToObservable() .SelectMany(x => Observable.Start(() => ProcessRecord(x), Scheduler.ThreadPoolScheduler)) .ToList() .First();
(Or, if you want the order of the elements to be maintained at the expense of efficiency):
records.ToObservable() .Select(x => Observable.Start(() => ProcessRecord(x), Scheduler.ThreadPoolScheduler)) .Concat() .ToList() .First();
Or if you want to limit the number of elements at a time:
records.ToObservable() .Select(x => Observable.Defer(() => Observable.Start(() => ProcessRecord(x), Scheduler.ThreadPoolScheduler))) .Merge(5 ) .ToList() .First();
source share