在Metro Style App中访问文本和Xml文件 [英] Access text and Xml files in Metro Style App

查看:53
本文介绍了在Metro Style App中访问文本和Xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个应用程序,它在win8启动时显示磁贴。通过访问系统中存在的文件来更新哪些磁贴。我使用后台任务每15分钟更新一次瓷砖。我的代码是用C ++编写的。但是我无法读取文件的内容..



void Class1 :: Run(IBackgroundTaskInstance ^ taskInstance)

{

     BackgroundTaskDeferral ^ deferral = taskInstance-> GetDeferral();

     TileUpdateManager :: CreateTileUpdaterForApplication() - >清除();

     TileUpdateManager :: CreateTileUpdaterForApplication() - > EnableNotificationQueue(true);

     Notifications();

     deferral-> Complete();
$


}


void Taskback1 :: Notifications()


{


concurrency :: task< StorageFile ^> getFileOperation(KnownFolders :: DocumentsLibrary-> GetFileAsync(" Tiles1.xml"));


getFileOperation.then([this](StorageFile ^ file)

    {

       return FileIO :: ReadTextAsync(file);

     ;})。then([this](concurrency :: task< String ^> previousOperation){

        String ^ timestamp;

 

    尝试{

         //数据包含在时间戳中

          timestamp = previousOperation.get();


        

      } catch(...){

         //未找到时间戳

    }

  });


}


山姆用于读取文件的e代码在MainPage.xaml.cpp中可以正常工作,但在我的BackgroundTask文件中不能正常工作Taskback.1.cpp。


是否还有一些其他函数可以从系统中访问BackgroundTask文件的文件。 。


我还使用了其他一些方法但失败了。

解决方案


我想这个错误可能是因为后台任务运行两次并尝试打开文件两次。


请检查此帖子

http://social.msdn.microsoft.com /论坛/ et-EE / winappswithcsharp / thread / 931a1b0d-2940-49cb-885d-80498f9d3cc1


最好的问候,

Jesse


I am creating an app, which show tiles at startup in win8. In which tiles are updated by accessing files present in my system. I use background task to update tiles every 15 minutes. My code is in C++. But i am not able to read the content of the file..

void Class1::Run(IBackgroundTaskInstance^ taskInstance)
{
    BackgroundTaskDeferral^ deferral = taskInstance->GetDeferral();
    TileUpdateManager::CreateTileUpdaterForApplication()->Clear();
    TileUpdateManager::CreateTileUpdaterForApplication()->EnableNotificationQueue(true);
    Notifications();
    deferral->Complete();

}

void Taskback1::Notifications()

{

concurrency::task<StorageFile^> getFileOperation( KnownFolders::DocumentsLibrary->GetFileAsync("Tiles1.xml"));

getFileOperation.then([this](StorageFile^ file)
    {
        return FileIO::ReadTextAsync(file);
    }).then([this](concurrency::task<String^> previousOperation) {
        String^ timestamp;
 
     try {
         // Data is contained in timestamp
            timestamp = previousOperation.get();

          
         } catch (...) {
         // Timestamp not found
     }
   });

}

The same code for reading file is works fine in MainPage.xaml.cpp but not in my BackgroundTask file Taskback1.cpp.

Are there some other functions to access files from the system for BackgroundTask file..

I also used some other methods but failed.

解决方案

Hi,

I guess this error maybe caused by the background task run twice and try to open a file twice.

Please check this thread
http://social.msdn.microsoft.com/Forums/et-EE/winappswithcsharp/thread/931a1b0d-2940-49cb-885d-80498f9d3cc1

Best regards,
Jesse


这篇关于在Metro Style App中访问文本和Xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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