在ThreadPool.RunAsync中读取SyndicationFeed [英] Reading SyndicationFeed in ThreadPool.RunAsync

查看:93
本文介绍了在ThreadPool.RunAsync中读取SyndicationFeed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Windows 8 Metro RSS Feed应用程序.因此,我正在实施一项后台任务,以检查是否有新的提要,如果有的话,请通知用户.我这样做如下:

I'm developing a Windows 8 Metro RSS Feed app. Therefore I'm implementing a Background Task to check if new feeds are available and inform the user if so. I do this as follows:

public sealed class UpdateCheck : IBackgroundTask
{
  public async void Run(IBackgroundTaskInstance taskInstance)
  {
    BackgroundTaskDeferral backgroundTaskDeferral = taskInstance.GetDeferral();

    await StartUpdateCheck();

    backgroundTaskDeferral.Complete();
  }

  public IAsyncAction StartUpdateCheck()
  {
    return ThreadPool.RunAsync(async o =>
      { 
        SyndicationClient client = new SyndicationClient();
        SyndicationFeed feed = await client.RetrieveFeedAsync(new Uri("http://.../feed.xml"));

        ApplicationDataContainer applicationDataContainer = ApplicationData.Current.LocalSettings;
        string lastFeedId = (string) applicationDataContainer.Values["LastFeedId"];

        if (lastFeedId != feed.Items.First().Id)
        {
          // inform user
        }
      });
  }
}

当我调试代码时,我想通过按F10跨过SyndicationFeed feed = await client.RetrieveFeedAsync(new Uri("http://.../feed.xml"));行,所以什么也没有发生.其他代码行不会执行.因此,当我在RetrieveFeedAsync方法之前之前设置断点时,该断点会被命中. 这行之后,没有断点被击中.

When I'm debugging the code and i want to step over the line SyndicationFeed feed = await client.RetrieveFeedAsync(new Uri("http://.../feed.xml")); by hitting F10, nothing happens. The further code lines don't get executed. So, when i set a breakpoint before the RetrieveFeedAsync method, the breakpoint gets hit. After this line, no breakpoint gets hit.

我正在读取代码中另一个位置上的RSS-Feed,该位置不是BackgroundTask(并且不在ThreadPool.RunAsync lambda表达式中),并且一切正常,因此ThreadPool.RunAsync方法可能会导致问题

I'm reading the RSS-Feeds on another position in the code, which is not a BackgroundTask (and not in a ThreadPool.RunAsync lambda expression) and there everything works fine, so the ThreadPool.RunAsync method might causes the problem.

推荐答案

在后台任务中不需要ThreadPool.RunAsync,它已经在单独的线程中运行.

There is no need for ThreadPool.RunAsync in a background task, it already runs in a separate thread.

这篇关于在ThreadPool.RunAsync中读取SyndicationFeed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆