在查看了这个博客阅读器教程后,我注意到在一个方法中进行了 14 个异步调用。这些都是同时运行还是并行运行?如果不是,那么当发生错误时会发生什么?其余的是否连续运行,还是整个方法都停止了?
示例代码:
public async Task GetFeedsAsync()
{
Task<FeedData> feed1 =
GetFeedAsync("http://windowsteamblog.com/windows/b/developers/atom.aspx");
Task<FeedData> feed2 =
GetFeedAsync("http://windowsteamblog.com/windows/b/windowsexperience/atom.aspx");
Task<FeedData> feed3 =
GetFeedAsync("http://windowsteamblog.com/windows/b/extremewindows/atom.aspx");
Task<FeedData> feed4 =
GetFeedAsync("http://windowsteamblog.com/windows/b/business/atom.aspx");
Task<FeedData> feed5 =
GetFeedAsync("http://windowsteamblog.com/windows/b/bloggingwindows/atom.aspx");
Task<FeedData> feed6 =
GetFeedAsync("http://windowsteamblog.com/windows/b/windowssecurity/atom.aspx");
Task<FeedData> feed7 =
GetFeedAsync("http://windowsteamblog.com/windows/b/springboard/atom.aspx");
Task<FeedData> feed8 =
GetFeedAsync("http://windowsteamblog.com/windows/b/windowshomeserver/atom.aspx");
// There is no Atom feed for this blog, so we use the RSS feed.
Task<FeedData> feed9 =
GetFeedAsync("http://windowsteamblog.com/windows_live/b/windowslive/rss.aspx");
Task<FeedData> feed10 =
GetFeedAsync("http://windowsteamblog.com/windows_live/b/developer/atom.aspx");
Task<FeedData> feed11 =
GetFeedAsync("http://windowsteamblog.com/ie/b/ie/atom.aspx");
Task<FeedData> feed12 =
GetFeedAsync("http://windowsteamblog.com/windows_phone/b/wpdev/atom.aspx");
Task<FeedData> feed13 =
GetFeedAsync("http://windowsteamblog.com/windows_phone/b/wmdev/atom.aspx");
Task<FeedData> feed14 =
GetFeedAsync("http://windowsteamblog.com/windows_phone/b/windowsphone/atom.aspx");
this.Feeds.Add(await feed1);
this.Feeds.Add(await feed2);
this.Feeds.Add(await feed3);
this.Feeds.Add(await feed4);
this.Feeds.Add(await feed5);
this.Feeds.Add(await feed6);
this.Feeds.Add(await feed7);
this.Feeds.Add(await feed8);
this.Feeds.Add(await feed9);
this.Feeds.Add(await feed10);
this.Feeds.Add(await feed11);
this.Feeds.Add(await feed12);
this.Feeds.Add(await feed13);
this.Feeds.Add(await feed14);
}