2016-05-18 101 views
2

我們可以通過async/await讀取RSS嗎?加載SyndicationFeed和異步/等待

XmlReader reader = XmlReader.Create("http://localhost/feeds/serializedFeed.xml"); 
SyndicationFeed feed = SyndicationFeed.Load(reader); 

任何線索?

+1

你的意思是這樣[這](http://stackoverflow.com/questions/14072639/reading-syndicationfeed-in-threadpool-runasync)? –

+0

@diiN_是的,你會介意提供一個答案嗎?問題是SyndicationClient可從最低支持的客戶端獲得 Windows 8 [Windows應用商店應用程序,桌面應用程序] https://msdn.microsoft.com/en-us/library/windows/apps/windows.web.syndication.syndicationclient.aspx –

回答

2

好的民謠,這裏是工作的解決方案

private void GetRSS(string rssUrl) 
     { 
      Task.Factory.StartNew(() => { 
       using (XmlReader r = XmlReader.Create(rssUrl)) 
       { 
        SyndicationFeed feed = SyndicationFeed.Load(r); 
        Action bindData =() => { 
         lstFeedItems.ItemsSource = feed.Items; 
        }; 
        this.Dispatcher.InvokeAsync(bindData); 
       } 
      }); 
     }