private void MergeSorter(ChartValues <int> list, int startPoint, int midPoint, int endPoint) { ChartValues <int> tempList = new ChartValues <int>(list.ToArray().DeepClone()); int leftCounter = startPoint; int rightCounter = midPoint + 1; for (int i = startPoint; i < endPoint + 1; i++) { this.Counter.Count++; if (this.AlgorithmStatus == TaskStatus.WaitingToRun) { while (this.AlgorithmStatus != TaskStatus.Running) { Task.Delay(50); } } if (this.Token.IsCancellationRequested) { return; } if (leftCounter == midPoint + 1) { list[i] = tempList[rightCounter]; rightCounter++; continue; } if (rightCounter == endPoint + 1) { list[i] = tempList[leftCounter]; leftCounter++; continue; } if (tempList[leftCounter] <= tempList[rightCounter]) { list[i] = tempList[leftCounter]; leftCounter++; } else { list[i] = tempList[rightCounter]; rightCounter++; } Thread.Sleep(this.SortingInfo.SortingDelay); } return; }