public async Task <Task> GenerateAlgorithmsStatistics() { var mockList = await dataManager.GetMocks(); foreach (var mock in mockList) { Console.WriteLine(mock.Id); Task <Dictionary <string, long> >[] taskArray = { Task <Dictionary <string, long> > .Factory.StartNew(() => DoComputation(() => GetIntArray(mock.SetOfData).BubbleSort(), AlgorithmsEnum.BubbleSorter.ToString()) ), Task <Dictionary <string, long> > .Factory.StartNew(() => DoComputation(() => GetIntArray(mock.SetOfData).BucketSort(), AlgorithmsEnum.BucketSorter.ToString()) ), Task <Dictionary <string, long> > .Factory.StartNew(() => DoComputation(() => GetIntArray(mock.SetOfData).CombSort(), AlgorithmsEnum.ComboSorter.ToString()) ) }; Task.WaitAll(taskArray); for (int i = 0; i < taskArray.Length; i++) { var data = taskArray[i].Result; if (data != null) { foreach (KeyValuePair <string, long> item in data) { var algorithm = await dataManager.GetAlgorithmAsync(item.Key); if (algorithm != null) { var algStat = new AlgorithmStatistic() { AlgorithmId = algorithm.Id, Date = DateTime.Now, ExecutedTime = item.Value, MockDataId = mock.Id }; await dataManager.AddAloritmStatisticAsync(algStat); } Console.WriteLine("Key: {0}, Value: {1}", item.Key, item.Value); } } } } return(Task.CompletedTask); }