/// <summary> /// Starts the tasks execution. /// </summary> /// <returns>If has reach the timeout false, otherwise true.</returns> public override void Start(IEnumerable <IChromosome> chromosomesWithNoFitness, IFitness fitnessFunction) { IsRunning = true; SetThreadPoolConfig(out int minWorker, out int minIOC, out int maxWorker, out int maxIOC); try { foreach (var c in chromosomesWithNoFitness) { Add(fitnessFunction.EvaluateAsync(c)); } // Need to verify, because TimeSpan.MaxValue passed to Task.WaitAll throws a System.ArgumentOutOfRangeException. if (Timeout == TimeSpan.MaxValue) { Task.WaitAll(Tasks.ToArray()); } else { Task.WaitAll(Tasks.ToArray(), Timeout); } } finally { // reset pool and clear the tasks IsRunning = false; Clear(); ResetThreadPoolConfig(minWorker, minIOC, maxWorker, maxIOC); } }
/// <summary> /// Starts the tasks execution. /// </summary> /// <returns>If has reach the timeout false, otherwise true.</returns> public override void Start(IEnumerable <IChromosome> chromosomesWithNoFitness, IFitness fitnessFunction) { var startTime = DateTime.Now; // For each Tasks passed to excutor, // run it one in linear way. foreach (var c in chromosomesWithNoFitness) { var task = fitnessFunction.EvaluateAsync(c); task.Wait(); // If take more time expected on Timeout property, // tehn stop thre running. if (DateTime.Now - startTime > Timeout) { Shared.Logger.Error("LinearTaskExecutor.Start: TimeOut Exceeded!"); return; } } IsRunning = false; Clear(); }