简体   繁体   English

Windows Store应用程序的多线程

[英]Multithreading with Windows Store Applications

We are currently creating a Windows Store Application which gains information from an RSS feed and inputs this information into an ObservableCollection. 我们目前正在创建一个Windows应用商店应用程序,它从RSS提要中获取信息并将此信息输入到ObservableCollection中。 The issue we are having is when the information is being gained, the Applications UI becomes unresponsive. 我们遇到的问题是,当获取信息时,应用程序UI变得无法响应。

In order to get around this, I thought about creating a new thread and calling the method within this. 为了解决这个问题,我想到了创建一个新线程并在其中调用该方法。 Though, after some research we realised that this was no longer possible in Windows Store Apps. 虽然经过一些研究后我们意识到在Windows应用商店应用中已不再可能。 How can we get around this? 我们怎么能解决这个问题呢?

The method that collects the information is below. 收集信息的方法如下。

public void getFeed()
{
    setupImages();
    string[] feedUrls = new string[] {
        "http://www.igadgetos.co.uk/blog/category/gadget-news/feed/",
        "http://www.igadgetos.co.uk/blog/category/gadget-reviews/feed/",
        "http://www.igadgetos.co.uk/blog/category/videos/feed/",
        "http://www.igadgetos.co.uk/blog/category/gaming/feed/",
        "http://www.igadgetos.co.uk/blog/category/jailbreak-2/feed/",
        "http://www.igadgetos.co.uk/blog/category/kickstarter/feed/",
        "http://www.igadgetos.co.uk/blog/category/cars-2/feed/",
        "http://www.igadgetos.co.uk/blog/category/software/feed/",
        "http://www.igadgetos.co.uk/blog/category/updates/feed/"
    };

    {
        try
        {
            XNamespace dc = "http://purl.org/dc/elements/1.1/";
            XNamespace content = "http://purl.org/rss/1.0/modules/content/";

            foreach (var feedUrl in feedUrls)
            {
                var doc = XDocument.Load(feedUrl);
                var feed = doc.Descendants("item").Select(c => new ArticleItem() //Creates a copy of the ArticleItem Class.
                {
                    Title = c.Element("title").Value,
                    //There are another 4 of these.
                    Post = stripTags(c.Element(content + "encoded").Value)                        }
                ).OrderByDescending(c => c.PubDate);
                this.moveItems = feed.ToList();

                foreach (var item in moveItems)
                {
                    item.ID = feedItems.Count;
                    feedItems.Add(item);
                }
            }
            lastUpdated = DateTime.Now;
        }
        catch
        {
            MessageDialog popup = new MessageDialog("An error has occured downloading the feed, please try again later.");
            popup.Commands.Add(new UICommand("Okay"));
            popup.Title = "ERROR";

            popup.ShowAsync();
        }
    }
}

How would we be able to cause the Application to not freeze as we gain this information, as Threading is not possible within Windows Store Applications. 当我们获取此信息时,我们如何能够使应用程序不冻结,因为在Windows应用商店应用程序中无法进行线程处理。

Eg - We planned to use; 例如 - 我们计划使用;

Thread newThread = new Thread(getFeed);
newThread.Start

You need to use the well documented async pattern for your operations that happen on the UI thread. 您需要为UI线程上发生的操作使用记录良好的异步模式。 The link given by Paul-Jan in the comments is where you need to start. Paul-Jan在评论中给出的链接是您需要开始的地方。 http://msdn.microsoft.com/en-us/library/windows/apps/hh994635.aspx http://msdn.microsoft.com/en-us/library/windows/apps/hh994635.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 禁用Windows Store应用程序 - Disabling windows store applications 将桌面应用程序发布到Windows应用商店 - Publishing desktop applications to windows store 适用于 Windows 应用商店应用程序的 NSoup 的替代品 - Alternative to NSoup for Windows Store Applications Windows 8将应用程序存储为企业软件 - Windows 8 Store applications as enterprise software 在Windows应用商店应用程序中递归获取文件和文件夹 - Get files & folders recursively in Windows Store Applications Windows Store应用程序的DisplayMemberPath =“ Value”的替代方案是什么? - What is the alternative for DisplayMemberPath=“Value” for Windows Store applications? 替代MSMQ以在Windows应用商店应用程序中使用 - Alternative to MSMQ for use in Windows Store Applications StackTrace替代Windows应用程序中的运行时项目 - StackTrace alternative for runtime projects in windows store applications Windows应用商店应用程序(.NET)上的SSDP(UDP) - SSDP (UDP) on Windows Store applications (.NET) Windows Mobile应用程序存储应用程序状态的“标准”方式是什么? - What is the “Standard” way to store application state for windows mobile applications?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM