Guest User

Untitled

a guest
Jan 23rd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. var simulationResults =
  2. Enumerable.Range(0, 10000)
  3. .AsParallel()
  4. .WithCancellation(token ?? CancellationToken.None)
  5. .Select(z =>
  6. {
  7. progressAction?.Invoke();
  8.  
  9. double aResult = someMethod()
  10.  
  11. if (double.IsNaN(aResult))
  12. {
  13. // todo: Find a way to Break the Parallel loop.
  14. }
  15.  
  16. return aResult;
  17. });
  18.  
  19. var simulationResults = new ConcurrentBag<double>();
  20. Parallel.For(0,1000,(i, loopState) =>
  21. {
  22. progressAction?.Invoke();
  23. double aResult = someMethod()
  24. if (double.IsNaN(aResult))
  25. {
  26. //or loopState.Break();
  27. loopState.Stop();
  28. }
  29. simulationResults.Add(aResult);
  30. });
Add Comment
Please, Sign In to add comment