I want to convert a for loop that increments the iterator by 2 each pass into a Parallel For loop using TPL. The data in no way depends on the order or restrictions, but I want to process the data only in every other element of my source array (which is _Datalist in the code below), therefore, it needs to be increased by 2.
My For Loop:
for (int i = 1; i < _DataList.Length - 1; i += 2) {
Is it possible to indicate a parallel loop that I want to increase by two instead of one?
Here's Parallel Loop, but obviously, I only increment by 1 every iteration:
Task.Factory.StartNew(() => Parallel.For(1, _DataList.Length, i => { // do work for _DataList[i] }) );
I could tell the inner body of the loop to ignore the odd values ββof i, but this is like litle messy - is there a way to do this in the loop initialization somehow?
c # parallel-processing task-parallel-library
Gareth
source share