سؤال

In a function, I would like to do a parallel processing of IEnumerable that is provided as an argument.

This IEnumerable is already a result of some chaining i.e.:

IEnumerable argument = InitialEnumerable.Select(x => DoHeavyProcessing(x))...

But to me it's opaque - I can't modify how this argument is created. I don't ad hoc know how it is constructed.

Now, when I call argument.AsParallel() it does no good - AsParallel() only parallelizes processing that is on the right-side of it, but all the work before is run sequentially.

Instead, I need to somehow parse this IEnumerable and "decorate" it so that heavy work is parallelized.

هل كانت مفيدة؟

المحلول

There is no way to do this. IEnumerable is specifically designed in such a way that you cannot fetch a given item until you have already fetched the item before it.

Whatever is generating the IEnumerable needs to be the one to provide some type of support for parallelizing the generation of these items.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top