コード例 #1
0
        private IList <SyndicationFeed> ParallelCrawl(IList <string> urls)
        {
            var tasks = urls.Select(url =>
            {
                return(httpClient.GetStreamAsync(url)
                       .ContinueWith(task =>
                {
                    using (Stream responseStream = task.Result)
                        using (XmlReader reader = XmlReader.Create(responseStream))
                        {
                            var rss10 = new Rss10FeedFormatter();

                            if (rss10.CanRead(reader))
                            {
                                rss10.ReadFrom(reader);
                                return rss10.Feed;
                            }

                            return SyndicationFeed.Load(reader);
                        }
                }));
            });

            return(Task.WhenAll(tasks).Result);
        }
コード例 #2
0
        private IList<SyndicationFeed> ParallelCrawl(IList<string> urls)
        {
            var tasks = urls.Select(url =>
            {
                return httpClient.GetStreamAsync(url)
                    .ContinueWith(task =>
                    {
                        using (Stream responseStream = task.Result)
                        using (XmlReader reader = XmlReader.Create(responseStream))
                        {
                            var rss10 = new Rss10FeedFormatter();

                            if (rss10.CanRead(reader))
                            {
                                rss10.ReadFrom(reader);
                                return rss10.Feed;
                            }

                            return SyndicationFeed.Load(reader);
                        }
                    });
            });

            return Task.WhenAll(tasks).Result;
        }