c# 溢出抛异常_c# – PLINQ查询给出溢出异常

我正在运行PLINQ查询,如下所示:

ParallelQuery winningCombos = from n in nextComboMaker.GetNextCombo()

.AsParallel().WithCancellation(_cancelSource.Token)

where ComboWasAWinner(n)

select n;

ConcurrentBag wins = new ConcurrentBag();

foreach (var winningCombo in winningCombos)

{

wins.Add(winningCombo);

if (wins.Count == _maxWinsAllowed)

break;

}

GetNextCombo方法只返回下一个字母和数字组合,可能达到数十亿/万亿.

现在,当我选择一个大于Int32允许大小的组合范围时抛出异常,它总是在它运行的组合计数器为2147483584时抛出.

我已经确定GetNextCombo中没有任何东西通过创建一个假组合来每次返回(做一个收益率返回“234gf24fa23 ……”等)

LINQ抛出异常:

System.AggregateException was unhandled by user code

Message=One or more errors occurred.

Source=System.Core

StackTrace:

at System.Linq.Parallel.QueryTaskGroupState.QueryEnd(Boolean userInitiatedDispose)

at System.Linq.Parallel.MergeExecutor`1.Execute[TKey](PartitionedStream`2 partitions, Boolean ignoreOutput, ParallelMergeOptions options, TaskScheduler taskScheduler, Boolean isOrdered, CancellationState cancellationState, Int32 queryId)

at System.Linq.Parallel.PartitionedStreamMerger`1.Receive[TKey](PartitionedStream`2 partitionedStream)

at System.Linq.Parallel.ForAllOperator`1.WrapPartitionedStream[TKey](PartitionedStream`2 inputStream, IPartitionedStreamRecipient`1 recipient, Boolean preferStriping, QuerySettings settings)

at System.Linq.Parallel.UnaryQueryOperator`2.UnaryQueryOperatorResults.ChildResultsRecipient.Receive[TKey](PartitionedStream`2 inputStream)

at System.Linq.Parallel.WhereQueryOperator`1.WrapPartitionedStream[TKey](PartitionedStream`2 inputStream, IPartitionedStreamRecipient`1 recipient, Boolean preferStriping, QuerySettings settings)

at System.Linq.Parallel.UnaryQueryOperator`2.UnaryQueryOperatorResults.ChildResultsRecipient.Receive[TKey](PartitionedStream`2 inputStream)

at System.Linq.Parallel.ScanQueryOperator`1.ScanEnumerableQueryOperatorResults.GivePartitionedStream(IPartitionedStreamRecipient`1 recipient)

at System.Linq.Parallel.UnaryQueryOperator`2.UnaryQueryOperatorResults.GivePartitionedStream(IPartitionedStreamRecipient`1 recipient)

at System.Linq.Parallel.UnaryQueryOperator`2.UnaryQueryOperatorResults.GivePartitionedStream(IPartitionedStreamRecipient`1 recipient)

at System.Linq.Parallel.QueryOperator`1.GetOpenedEnumerator(Nullable`1 mergeOptions, Boolean suppressOrder, Boolean forEffect, QuerySettings querySettings)

at System.Linq.Parallel.ForAllOperator`1.RunSynchronously()

at StockWiz.Library.PLINQArrayProcessor.DoProcessing() in C:\Users\dad\Documents\BitBucket\stockwiz_clone\stockwiz\StockWiz.Library\PLINQArrayProcessor.cs:line 50

at System.Threading.Tasks.Task.Execute()

InnerException: System.OverflowException

Message=Arithmetic operation resulted in an overflow.

Source=System.Core

StackTrace:

at System.Linq.Parallel.PartitionedDataSource`1.ContiguousChunkLazyEnumerator.MoveNext(T& currentElement, Int32& currentKey)

at System.Linq.Parallel.WhereQueryOperator`1.WhereQueryOperatorEnumerator`1.MoveNext(TInputOutput& currentElement, TKey& currentKey)

at System.Linq.Parallel.ForAllOperator`1.ForAllEnumerator`1.MoveNext(TInput& currentElement, Int32& currentKey)

at System.Linq.Parallel.ForAllSpoolingTask`2.SpoolingWork()

at System.Linq.Parallel.SpoolingTaskBase.Work()

at System.Linq.Parallel.QueryTask.BaseWork(Object unused)

at System.Threading.Tasks.Task.Execute()

InnerException:

我想知道是否有任何我可以做的事情来改变这个查询不溢出,我做任何事情的顺序,等等.也许没有linq查询做的地方和选择,虽然我试过这个:

var query = nextComboMaker.GetNextCombo().AsParallel();

query.ForAll(x => if(ComboWasAWinner(x) wins.Add(x) );

还是一样的溢出.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值