I have an order by linq query, something like this like this:
var sortedList = unsortedList
.OrderBy(foo => foo.GetCurrentValue())
However, the method GetCurrentValue responds slowly (because it involves network communication and has considerable latency). As far as I observe, the code aboves call the method sequentally (a call has to finish before the next one is called, so if the list is long the sorting will be really slow.
Is there a way to tell linq to do it in parallel? i.e. evaluate the expression asynchronously and then compare the result after everyone is finished?
If not, any idea how to make our own implementation cleanly and easily?
The MSDN has an article specifically on “Order Preservation” in PLINQ – http://msdn.microsoft.com/en-us/library/dd460677.aspx (per my earlier comment). An example given by the link:
And just throwing it out there as a possible implementation, something like this? Where
slowListis an enumerable collection of your “slow” objects. TheParallel.ForEachcould be substituted with any other async “staging” operation for gathering the slow values.