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方法時起作用):