/// <summary> /// Выполняем один проход по вертикали и горизонтали /// </summary> /// <returns></returns> private bool SolveIter() { bool isChanged = false; Task[] rowThreads = new Task[threadCount]; object lockObj = new object(); for (Byte i = 0; i < rowThreads.Length; i++) { rowThreads[i] = Task.Factory.StartNew((threadIndex) => { for (int j = (byte)threadIndex; j < solvedSudocu.Size.Height; j += rowThreads.Length) { if (!RowChanged[j]) { bool res = SolveRow((byte)j); lock (lockObj) { isChanged |= res; } RowChanged[j] = true; ProgressEvent.BeginInvoke(null, null); } } }, i); } Task.WaitAll(rowThreads); Task[] collThreads = new Task[threadCount]; for (Byte i = 0; i < collThreads.Length; i++) { collThreads[i] = Task.Factory.StartNew((threadIndex) => { int count = System.Math.Min(((byte)threadIndex + 1) * 10, solvedSudocu.Size.Width); for (int j = (byte)threadIndex; j < solvedSudocu.Size.Width; j += collThreads.Length) { if (!ColumnChanged[j]) { bool res = SolveColumn((byte)j); lock (lockObj) { isChanged |= res; } ColumnChanged[j] = true; ProgressEvent.BeginInvoke(null, null); } } }, i); } Task.WaitAll(collThreads); return(!isChanged); }