public async Task <ActionResult> NewsAsyncAsync() { DateTime dt1 = DateTime.Now; var rss = new string[] { "http://articles.csdn.net/api/rss.php?tid=1008", "http://aspnet.codeplex.com/project/feeds/rss", "http://solidot.org.feedsportal.com/c/33236/f/556826/index.rss", "http://www.codeguru.com/icom_includes/feeds/codeguru/rss-csharp.xml", "http://feed.google.org.cn/" }; List <List <NewsItem> > list = new List <List <NewsItem> >(); foreach (var item in rss) { List <NewsItem> news = await(NewsModels.GetNews(item)); list.Add(news); } var model = list.SelectMany(x => x) .ToList() .OrderByDescending(x => x.PostDate) .Take(100); DateTime dt2 = DateTime.Now; ViewBag.TimeCost = new TimeSpan(dt2.Ticks - dt1.Ticks).ToString(); return(View("News", model)); }
public ActionResult NewsSync() { DateTime dt1 = DateTime.Now; var rss = new string[] { "http://articles.csdn.net/api/rss.php?tid=1008", "http://aspnet.codeplex.com/project/feeds/rss", "http://solidot.org.feedsportal.com/c/33236/f/556826/index.rss", "http://www.codeguru.com/icom_includes/feeds/codeguru/rss-csharp.xml", "http://feed.google.org.cn/" }; var model = rss.SelectMany(x => NewsModels.GetNews(x).Result) .ToList() .OrderByDescending(x => x.PostDate) .Take(100); DateTime dt2 = DateTime.Now; ViewBag.TimeCost = new TimeSpan(dt2.Ticks - dt1.Ticks).ToString(); return(View("News", model)); }