Can somebody explain me one thing. As I understand AsParallel() executes in own task. So, if query return huge amount of data the variable 'd' can be empty at time when 'foreach' started to execute Console.WriteLine?
var integerList = Enumerable.Range(1, 100);
var d = from x in integerList.AsParallel()
where x <= 25
select x;
foreach (var v in d)
{
Console.WriteLine(v);
}
AsParallel
is a PLINQ
feature.
PLINQ
automatically parallelizes local LINQ
queries. PLINQ
has the advantage of being easy to use in that it offloads the burden of both work partitioning and result collation to the Framework.
To use PLINQ
, simply call AsParallel()
on the input sequence and then continue the LINQ
query as usual.
Variable d
in your case can not be empty only because PLINQ
. If it will be empty that means there is no elements in the collection that satisfy the condition x <= 25
.
You can read more here
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