Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var simulationResults =
- Enumerable.Range(0, 10000)
- .AsParallel()
- .WithCancellation(token ?? CancellationToken.None)
- .Select(z =>
- {
- progressAction?.Invoke();
- double aResult = someMethod()
- if (double.IsNaN(aResult))
- {
- // todo: Find a way to Break the Parallel loop.
- }
- return aResult;
- });
- var simulationResults = new ConcurrentBag<double>();
- Parallel.For(0,1000,(i, loopState) =>
- {
- progressAction?.Invoke();
- double aResult = someMethod()
- if (double.IsNaN(aResult))
- {
- //or loopState.Break();
- loopState.Stop();
- }
- simulationResults.Add(aResult);
- });
Add Comment
Please, Sign In to add comment