private static bool Iteration(RenderSequenceModel rsm, Stopwatch stopwatch, bool countShots, out int shots) { shots = 0; var shotsParallel = new int[0]; if (countShots) { shotsParallel = new int[rsm.Cores]; } #region render parallel var cx = rsm.CenterPoint.X; var cy = rsm.CenterPoint.Y; IsRendering = true; try { _sourceParallel?.Token.ThrowIfCancellationRequested(); } catch (OperationCanceledException) { EndRender(rsm.Display, rsm.TotalIterations, stopwatch.Elapsed, rsm.RenderActionsPack, $"render interrupted (RenderValidity) {rsm.RenderId}", rsm.DraftMode, rsm.RenderId); return(false); } lock (LockObj) { _sourceParallel = new CancellationTokenSource(); } var parallelOptions = new ParallelOptions { CancellationToken = _sourceParallel.Token, MaxDegreeOfParallelism = rsm.Cores }; try { Parallel.For(0, rsm.Cores, parallelOptions, core => { var iterator = rsm.Iterators[core]; iterator.Iterate(rsm.TotalPointsPerCore); try { for (var i = 0; i < rsm.TotalPointsPerCore; i++) { var p = i * 2; var pX = iterator.Points[p]; var pY = iterator.Points[p + 1]; var colorId = iterator.ColorIds[i]; for (var s = 0; s < rsm.Symmetry; s++) { Trigonometry.TranslatePoint(pX, pY, rsm.TranslationArray, cx, cy, out var tpX, out var tpY); if (Trigonometry.InRange(tpX, tpY, rsm.ImageSize)) { rsm.Display.Shot((uint)tpX, (uint)tpY, colorId); if (countShots) { shotsParallel[core]++; } } if (s < rsm.Symmetry - 1) { Trigonometry.RotatePoint(ref pX, ref pY, rsm.SectorCos, rsm.SectorSin); } } parallelOptions.CancellationToken.ThrowIfCancellationRequested(); }