I need detect rebooting or device starting, to do this I followed this topic (Detecting reboot programmatically in Windows Phone 8.1), but in my case the method canceled is never called in background task.
When I starting debug, my method is called after forcing changes in timezone that made by:
builder.SetTrigger(new SystemTrigger(SystemTriggerType.TimeZoneChange, false));
public void Run(IBackgroundTaskInstance taskInstance)
BackgroundTaskDeferral defferal = taskInstance.GetDeferral();
taskInstance.Canceled += TaskInstance_Canceled;
private async void TaskInstance_Canceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason)
BackgroundTaskDeferral defferal = sender.GetDeferral();
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);
After using some hours in this problem, I found the solution, Windows Phone have a System Trigger type that is called when device is booted, named: SessionConnected.
Thus, only need simple changes:
builder.SetTrigger(new SystemTrigger(SystemTriggerType.SessionConnected, false));