首页 > c# > 加载SyndicationFeed和async / await

加载SyndicationFeed和async / await (Load SyndicationFeed and async/await)

问题

我们可以通过async / await阅读RSS吗?

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

任何线索?

解决方法

您的解决方案不使用async / await,代码太多,我怀疑您的方法在某些情况下容易出现死锁。

只需这样做

var reader = XmlReader.Create("http://localhost/feeds/serializedFeed.xml");
var feed = await Task.Run(() => SyndicationFeed.Load(reader));

问题

Can we read RSS by async/await?

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

Any clue?

解决方法

Your solution is not using async/await, has too much code, and I suspect your approach is prone to deadlocks under certain scenarios.

Simply do this

var reader = XmlReader.Create("http://localhost/feeds/serializedFeed.xml");
var feed = await Task.Run(() => SyndicationFeed.Load(reader));
相似信息