Search code examples
c#.netasync-awaitxmlreadersyndicationfeed

Load SyndicationFeed and async/await


Can we read RSS by async/await?

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

Any clue?


Solution

  • 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));