示例#1
0
        public void Step(int MaxThreads = 4)
        {
            ParallelOptions pOptions = new ParallelOptions
            {
                MaxDegreeOfParallelism = MaxThreads
            };

            Parallel.For(0, CurrentGeneration.Height, pOptions, y =>
            {
                for (int x = 0; x < CurrentGeneration.Width; x++)
                {
                    int AliveNeighbors = CurrentGeneration.GetAliveNeighbours(x, y);
                    bool isAlive       = CurrentGeneration.IsAlive(x, y);

                    if (isAlive && (AliveNeighbors == 2 || AliveNeighbors == 3))
                    {
                        NextGeneration.SetPixel(x, y, true);
                    }
                    else if (!isAlive && AliveNeighbors == 3)
                    {
                        NextGeneration.SetPixel(x, y, true);
                    }
                    else
                    {
                        NextGeneration.SetPixel(x, y, false);
                    }
                }
            });
        }