Is PLINQ guaranteed to return query results in the order of the original sequence being operated on, even if results are produced in parallel? For instance:
new List<String>(){"a", "b", "c", "d"}.asParallel().Select(str => str + "a").asSequential().ToList().ForEach(str => Console.Write(str + ", ");
will the result always be "aa, ba, ca, da, "?
You have to use AsOrdered()
to preserve the order:
new List<String>(){"a", "b", "c", "d"}
.AsParallel()
.AsOrdered()
.Select(str => str + "a")
.AsSequential()
.ToList()
.ForEach(str => Console.Write(str + ", "));
Also check out this: How to: Control Ordering in a PLINQ Query
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With