I’m trying to put together a simple RSS feed reader in windows phone 7 but I’m struggling to understand how the async model works.
What I have is a helper class that when I pass it a URL will parse and build up a ViewModel object and return it. So what I am trying to acheive is this:
public static class FeedHelper
{
public static FeedViewModel LoadFeed(string url)
{
//parse rss feed and return view model
}
}
In the loadfeed method I would make a webclient object and build up the FeedViewModel. However because the WebClient’s DownloadStringAsync is async and the result is returned to another method I can’t figure out how I can return the FeedViewModel from my LoadFeed method.
Any examples or links to blog posts would be appreciated. I’ve done quite a bit of googling but can’t find any examples of how I would approach this problem.
You cannot return the ViewModel from your LoadFeed function because as you discovered, the call is async.
You have several choices, for ex. you could: