public async Task <ActionResult> CreateSitemap(string url) { var entireWatch = Stopwatch.StartNew(); var links = _sitemapService.GetLinks(url); var sitemap = _repository.AddSitemap(url); var sitemapLinks = new List <SitemapLink>(); var tasks = new List <Task>(); foreach (var link in links) { var task = new Task(() => { var info = new SitemapLink { HttpAddress = link }; var watch = Stopwatch.StartNew(); var result = _client.GetAsync(link).Result; watch.Stop(); info.ShortestTime = watch.ElapsedMilliseconds; info.LongestTime = watch.ElapsedMilliseconds; sitemapLinks.Add(info); info.Sitemap = sitemap; }); tasks.Add(task); task.Start(); task.Wait(); } entireWatch.Stop(); _repository.AddSitemapLinks(sitemap.Id, sitemapLinks); ViewBag.LinkName_List = string.Join(",", sitemapLinks.Select(c => string.Format("'{0}'", c.HttpAddress)).ToList()); ViewBag.LongestTime_List = string.Join(",", sitemapLinks.Select(c => c.LongestTime).ToList()); ViewBag.ShortestTime_List = string.Join(",", sitemapLinks.Select(c => c.ShortestTime).ToList()); return(View(sitemapLinks.OrderByDescending(u => u.LongestTime).ToList())); }