0

如何使用后台任务更改 Windows.Storage.ApplicationData.Current.LocalSettings 中的值。我使用像后台任务这样的代码:

namespace MainTask
{
    public sealed class Task :IBackgroundTask
    {
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            BackgroundTaskDeferral _deferral = taskInstance.GetDeferral();
            var storage = Windows.Storage.ApplicationData.Current.LocalSettings;
            int i = (int)storage.Values["var"];
            i++;

            storage.Values["val"] = i;

            _deferral.Complete();
        }
    }
}

后台任务已启动,调试器中有 livecycle 事件,它读取存储。但是 Values["val"] 不会改变。

4

1 回答 1

0
namespace MainTask
{
    public sealed class Task :IBackgroundTask
    {
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            BackgroundTaskDeferral _deferral = taskInstance.GetDeferral();
            var storage = Windows.Storage.ApplicationData.Current.LocalSettings;
            int i = (int)storage.Values["var"];
            i++;

            storage.Values.Remove("val");
            storage.Values.Add("val", i);

            _deferral.Complete();
        }
    }
}
于 2015-03-28T18:53:59.793 回答