public Deviation GetDeviation(double[] numbers, int deviationPercent) { var avg = new AvarageDeviationMeans(); var ballancedKMeans = new AvarageDeviationMeans(); Deviation dev = null; var task = Task.Run(() => dev = ballancedKMeans.GetDeviation(numbers, deviationPercent)); if (Task.WhenAny(task, Task.Delay(3000)).Result == task) { return(dev); } else { return(avg.GetDeviation(numbers, deviationPercent)); } }