0
我需要检测重新启动或设备启动,为此,我遵循此主题(Detecting reboot programmatically in Windows Phone 8.1),但在我的情况下,取消的方法从不会在后台任务中调用。当设备重新启动或在Windows Phone 8.1中启动时检测到
当我开始调试,我的方法是迫使时区,通过进行更改后叫:
builder.SetTrigger(new SystemTrigger(SystemTriggerType.TimeZoneChange, false));
我的后台任务是:
public void Run(IBackgroundTaskInstance taskInstance)
{
BackgroundTaskDeferral defferal = taskInstance.GetDeferral();
taskInstance.Canceled += TaskInstance_Canceled;
defferal.Complete();
}
private async void TaskInstance_Canceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason)
{
BackgroundTaskDeferral defferal = sender.GetDeferral();
try
{
StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
await localFolder.CreateFileAsync("bruno.txt", CreationCollisionOption.OpenIfExists);
}
catch (Exception e)
{
Debug.WriteLine("Fail to create File test: " + e);
}
defferal.Complete();
}
我知道这是从来没有所谓的,因为下一个例程始终是假的(它在当应用程序启动MainPage方法时起作用):