PLINQ query providing overflow exception

I run the PLINQ query as follows:

ParallelQuery<string> winningCombos = from n in nextComboMaker.GetNextCombo() .AsParallel().WithCancellation(_cancelSource.Token) where ComboWasAWinner(n) select n; ConcurrentBag<string> wins = new ConcurrentBag<string>(); foreach (var winningCombo in winningCombos) { wins.Add(winningCombo); if (wins.Count == _maxWinsAllowed) break; } 

The GetNextCombo method simply returns the following combination of letters and numbers with capabilities up to billions / trillions.

Now this throws an exception when I select a range of combinations that exceeds the Int32 allowable size, it always throws when the combo counter that it launches is 2147483584.

In GetNextCombo, I did nothing by creating a fake combo to return every time (returning the income of "234gf24fa23 ...", etc.)

The exception is 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: 

I am wondering if there is anything that I can do to change this request so as not to overflow, any order in which I do something, etc. Perhaps there is no linq request to do something and select, although I tried this:

  var query = nextComboMaker.GetNextCombo().AsParallel(); query.ForAll(x => if(ComboWasAWinner(x) wins.Add(x) ); 

all the same overflow.

+6
source share
1 answer

You can get around this using a custom delimiter. By default, the default delimiter selected by PLINQ only supports the number of elements within a range.

For more information on how to do this, see http://msdn.microsoft.com/en-us/library/dd997416.aspx .

+6
source

All Articles