private void RegisterBackgroundTask() { var task = BackgroundTaskSample.RegisterBackgroundTask(BackgroundTaskSample.SampleBackgroundTaskEntryPoint, BackgroundTaskSample.SampleBackgroundTaskWithConditionName, new SystemTrigger(SystemTriggerType.UserAway, false), null); AttachProgressAndCompletedHandlers(task); UpdateUI(); }
protected override void OnNavigatedTo(NavigationEventArgs e) { foreach (var task in BackgroundTaskRegistration.AllTasks) { AttachProgressAndCompletedHandlers(task.Value); BackgroundTaskSample.UpdateBackgroundTaskStatus(BackgroundTaskSample.TimeTriggeredTaskName, true); } base.OnNavigatedTo(e); }
private void DoYourBackgroundWork(IBackgroundTaskInstance taskInstance) { IBackgroundTask task = null; if (taskInstance.Task.Name == "MyBackgroundTask") { task = new BackgroundTaskSample(); } task?.Run(taskInstance); }
/// <summary> /// Register a TimeTriggeredTask. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void RegisterBackgroundTask(object sender, RoutedEventArgs e) { // // Time triggered tasks can only run when the application is on the lock screen. // Time triggered tasks can be registered even if the application is not on the lockscreen. // await BackgroundExecutionManager.RequestAccessAsync(); var task = BackgroundTaskSample.RegisterBackgroundTask(BackgroundTaskSample.SampleBackgroundTaskEntryPoint, BackgroundTaskSample.TimeTriggeredTaskName, new TimeTrigger(30, false), null); AttachProgressAndCompletedHandlers(task); }
private Boolean AttachTask() { Boolean _status = false; foreach (var task in BackgroundTaskRegistration.AllTasks) { if (task.Value.Name == BackgroundTaskSample.SampleBackgroundTaskWithConditionName) { _status = true; AttachProgressAndCompletedHandlers(task.Value); BackgroundTaskSample.UpdateBackgroundTaskStatus(BackgroundTaskSample.SampleBackgroundTaskWithConditionName, true); break; } } return(_status); }
/// <summary> /// Unregister a TimeTriggeredTask. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UnregisterBackgroundTask(object sender, RoutedEventArgs e) { BackgroundTaskSample.UnregisterBackgroundTasks(BackgroundTaskSample.TimeTriggeredTaskName); }
private void UnregisterBackgroundTask() { BackgroundTaskSample.UnregisterBackgroundTasks(BackgroundTaskSample.SampleBackgroundTaskWithConditionName); UpdateUI(); }