I want to divide for loop between Tasks.
Sample code that should describe my idea:
for(int i = 0; i < array.Length; i++)
{
array[i].Function(); //void method
}
For example if array count is 20, and I have set chunk count to 4, it will give us chunk size 5. First task will handle i from 0 to 4, second 5 to 9, 10 to 14, 15 to 19. And it's optimistic case, if number is odd, you need additional task to handle a few elements.
And I can't solve two issues:
- How to divide it knowing that depending on chunk count, chunk size can be even or odd.
- How to declare Tasks knowing the above.
Before someone says that I should try myself first: if I would know what to do, I would try. I'm asking because I don't know. This is the purpose of a forum. Wild idea, I know.