You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET 8中PLINQ行为与.NET 7不一致的问题咨询

.NET 8中PLINQ并行执行行为的异常疑问

测试代码

using System;
using static System.Console;
var numbers = Enumerable.Range(0, 31);

WriteLine("\nNumbers divisible by 5 are(using LINQ):");
numbers
.Where(num => num % 5 == 0)
.ToList()
.ForEach(num => Write($"{num}\t"));

WriteLine("\nNumbers divisible by 5 are(using PLINQ):");
numbers
.AsParallel()
.Where(num => num % 5 == 0)
.ToList()
.ForEach(num => Write($"{num}\t"));


WriteLine("\nNumbers divisible by 5 are(using PLINQ with forcing parallelism):");
numbers
.AsParallel()
.WithExecutionMode(ParallelExecutionMode.ForceParallelism)
.Where(num => num % 5 == 0)
.ToList()
.ForEach(num => Write($"{num}\t"));

.NET 7 示例输出(预期行为)

Numbers divisible by 5 are(using LINQ):
0       5       10      15      20      25      30
Numbers divisible by 5 are(using PLINQ):
5       20      25      0       30      15      10
Numbers divisible by 5 are(using PLINQ with forcing parallelism):
25      30      0       5       10      15      20

.NET 8 实际输出

Numbers divisible by 5 are(using LINQ):
0       5       10      15      20      25      30
Numbers divisible by 5 are(using PLINQ):
0       5       10      15      20      25      30
Numbers divisible by 5 are(using PLINQ with forcing parallelism):
0       5       10      15      20      25      30

我认为.NET 8中的PLINQ引擎存在故障,若有考虑不周的地方请指正。显然.NET 7与.NET 8中PLINQ的行为存在明显差异,且.NET 8的行为不符合预期,欢迎各位分享见解。

内容的提问来源于stack exchange,提问作者Vaskaran Sarcar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 09:51:24