如何使用后台任务更改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();
}
}
}
后台任务已启动,调试器中存在实时循环事件,它会读取存储。但是值[“val”]不会改变。
答案 0 :(得分: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();
}
}
}