小编Sna*_*hia的帖子

在WP7中下载内容期间在UI中冻结

我是WP7编码的新手.我正在寻找示例代码或指导以下任务:

我在远程服务器上有3个html页面,我想下载每个页面的内容并将其发布到3个不同的全景页面(显示为文本块).

我写了3套webclient来加载html页面; 它可以显示为它所假设的位置.我面临的问题是,在下载时/期间,UI线程是"freez"并且没有响应.

任何人都可以指导我/向我展示示例代码,我可以将线程放到后台,一旦完成,并在UI中显示?

这是我用来下载HTML页面的代码.

private async void GetNewsIndex(string theN)
    {
        string newsURI = newsURL + theN;
        string fileName = theN + "-temp.html";
        string folderName = "news";

        prgBar01.Visibility = System.Windows.Visibility.Visible;

        try
        {
            Task<string> contentDataDownloaded = new WebClient().DownloadStringTaskAsync(new Uri(newsURI));

            string response = await contentDataDownloaded;

            WriteTempFile(theN, response.ToString());

            string contentData = ProcessDataToXMLNews(fileName, folderName);

            WritenewsIndexXMLFile(newsIndexURI, folderName, contentData);

            DisplayNewsIndex();

        }
        catch
        {
            //
        }
    }
Run Code Online (Sandbox Code Playgroud)

我根据Sinh Pham的建议修改了上面的代码,它完美地按预期工作.但是,因为我需要运行它的3个瞬间来同时从不同的源下载页面; 代码中断.任何的想法?

c# user-interface windows-phone-7

5
推荐指数
1
解决办法
809
查看次数

标签 统计

c# ×1

user-interface ×1

windows-phone-7 ×1