Get next element in foreach loop

A unique approach would be to reverse the array and then loop. This will work for non-numerically indexed arrays as well: $items = array( ‘one’ => ‘two’, ‘two’ => ‘two’, ‘three’ => ‘three’ ); $backwards = array_reverse($items); $last_item = NULL; foreach ($backwards as $current_item) { if ($last_item === $current_item) { // they match } $last_item … Read more

Why is Parallel.ForEach much faster then AsParallel().ForAll() even though MSDN suggests otherwise?

This problem is pretty debuggable, an uncommon luxury when you have problems with threads. Your basic tool here is the Debug > Windows > Threads debugger window. Shows you the active threads and gives you a peek at their stack trace. You’ll easily see that, once it gets slow, that you’ll have dozens of threads … Read more