I have a task that essentially loops through a collection and does an operation on them in pairs (for int i = 0; i < limit; i+=2 etc.) And so, most suggestions I see on threading loops use some sort of foreach mechanism. But that seems a bit tricky to me, seeing as how I use this approach of operating in pairs.
So what I would want to do is essentially replace:
DoOperation(list.Take(numberToProcess));
with
Thread lowerHalf = new Thread(() => => DoOperation(list.Take(numberToProcess/2)));
Thread lowerHalf = new Thread(() => => DoOperation(list.getRange(numberToProcess/2, numberToProcess));
lowerHalf.Start();
upperHalf.Start();
And this seems to get the work done, but it's VERY slow. Every iteration is slower than the previous one, and when I debug, the Thread view shows a growing list of Threads.
But I was under the impression that Threads terminated themselves upon completion? And yes, the threads do complete. The DoOperation() method is pretty much just a for loop.
So what am I not understanding here?