/// <summary> /// Unregisters all Background Tasks that are not in groups. /// This will not impact tasks registered with groups. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UnregisterUngroupedTasks(object sender, RoutedEventArgs e) { foreach (var cur in BackgroundTaskRegistration.AllTasks) { cur.Value.Unregister(true); BackgroundTaskSample.UpdateBackgroundTaskRegistrationStatus(cur.Value.Name, false); } }
/// <summary> /// Register a ApplicationTriggerTask. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RegisterBackgroundTask(object sender, RoutedEventArgs e) { var task = BackgroundTaskSample.RegisterBackgroundTask(BackgroundTaskSample.SampleBackgroundTaskEntryPoint, BackgroundTaskSample.ApplicationTriggerTaskName, trigger, null); AttachProgressAndCompletedHandlers(task); UpdateUI(); }
/// <summary> /// Register a TimeTriggeredTask. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RegisterBackgroundTask(object sender, RoutedEventArgs e) { var task = BackgroundTaskSample.RegisterBackgroundTask(null, BackgroundTaskSample.TimeTriggeredTaskName, new TimeTrigger(15, false), null); AttachProgressAndCompletedHandlers(task); UpdateUI(); }
/// <summary> /// Register a ServicingCompleteTask. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RegisterBackgroundTask(object sender, RoutedEventArgs e) { var task = BackgroundTaskSample.RegisterBackgroundTask(null, BackgroundTaskSample.ServicingCompleteTaskName, new SystemTrigger(SystemTriggerType.ServicingComplete, false), null); AttachProgressAndCompletedHandlers(task); UpdateUI(); }
/// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { this.InitializeComponent(); this.Suspending += new SuspendingEventHandler(OnSuspending); // // Register a background task with the servicing complete event. // BackgroundTaskSample.RegisterServicingCompleteTask(); }
/// <summary> /// Register a SampleBackgroundTaskWithCondition. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RegisterBackgroundTask(object sender, RoutedEventArgs e) { var task = BackgroundTaskSample.RegisterBackgroundTask(null, BackgroundTaskSample.SampleBackgroundTaskWithConditionName, new SystemTrigger(SystemTriggerType.TimeZoneChange, false), new SystemCondition(SystemConditionType.InternetAvailable)); AttachProgressAndCompletedHandlers(task); UpdateUI(); }
/// <summary> /// Register a SampleBackgroundTask. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RegisterBackgroundTask(object sender, RoutedEventArgs e) { var task = BackgroundTaskSample.RegisterBackgroundTask(BackgroundTaskSample.SampleBackgroundTaskEntryPoint, BackgroundTaskSample.SampleBackgroundTaskName, new SystemTrigger(SystemTriggerType.TimeZoneChange, false), null); AttachProgressAndCompletedHandlers(task); UpdateUI(); }
/// <summary> /// Update the scenario UI. /// </summary> private async void UpdateUI() { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { RegisterButton.IsEnabled = !BackgroundTaskSample.SampleBackgroundTaskWithConditionRegistered; UnregisterButton.IsEnabled = BackgroundTaskSample.SampleBackgroundTaskWithConditionRegistered; Progress.Text = BackgroundTaskSample.SampleBackgroundTaskWithConditionProgress; Status.Text = BackgroundTaskSample.GetBackgroundTaskStatus(BackgroundTaskSample.SampleBackgroundTaskWithConditionName); }); }
/// <summary> /// Register a ServicingCompleteTask. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void RegisterBackgroundTask(object sender, RoutedEventArgs e) { var task = BackgroundTaskSample.RegisterBackgroundTask(BackgroundTaskSample.ServicingCompleteTaskEntryPoint, BackgroundTaskSample.ServicingCompleteTaskName, new SystemTrigger(SystemTriggerType.ServicingComplete, false), null); await task; AttachProgressAndCompletedHandlers(task.Result); UpdateUI(); }
/// <summary> /// Update the scenario UI. /// </summary> private async void UpdateUI() { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { RegisterButton.IsEnabled = !BackgroundTaskSample.ServicingCompleteTaskRegistered; UnregisterButton.IsEnabled = BackgroundTaskSample.ServicingCompleteTaskRegistered; Progress.Text = BackgroundTaskSample.ServicingCompleteTaskProgress; Status.Text = BackgroundTaskSample.GetBackgroundTaskStatus(BackgroundTaskSample.ServicingCompleteTaskName); }); }
/// <summary> /// Update the scenario UI. /// </summary> private async void UpdateUI() { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { RegisterButton.IsEnabled = !BackgroundTaskSample.ApplicationTriggerTaskRegistered; UnregisterButton.IsEnabled = BackgroundTaskSample.ApplicationTriggerTaskRegistered; SignalButton.IsEnabled = BackgroundTaskSample.ApplicationTriggerTaskRegistered & (trigger != null); Progress.Text = BackgroundTaskSample.ApplicationTriggerTaskProgress; Result.Text = BackgroundTaskSample.ApplicationTriggerTaskResult; Status.Text = BackgroundTaskSample.GetBackgroundTaskStatus(BackgroundTaskSample.ApplicationTriggerTaskName); }); }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.</param> protected override void OnNavigatedTo(NavigationEventArgs e) { foreach (var task in BackgroundTaskRegistration.AllTasks) { if (task.Value.Name == BackgroundTaskSample.ServicingCompleteTaskName) { AttachProgressAndCompletedHandlers(task.Value); BackgroundTaskSample.UpdateBackgroundTaskStatus(BackgroundTaskSample.ServicingCompleteTaskName, true); break; } } UpdateUI(); }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.</param> protected override void OnNavigatedTo(NavigationEventArgs e) { group = BackgroundTaskSample.GetTaskGroup(BackgroundTaskSample.BackgroundTaskGroupId, BackgroundTaskSample.BackgroundTaskGroupFriendlyName); foreach (var task in group.AllTasks) { if (task.Value.Name == BackgroundTaskSample.GroupedBackgroundTaskName) { AttachProgressAndCompletedHandlers(task.Value); BackgroundTaskSample.UpdateBackgroundTaskRegistrationStatus(BackgroundTaskSample.GroupedBackgroundTaskName, true); break; } } UpdateUI(); }
/// <summary> /// Register for grouped background task events in the Application constructor. /// </summary> partial void Construct() { var group = BackgroundTaskSample.GetTaskGroup(BackgroundTaskSample.BackgroundTaskGroupId, BackgroundTaskSample.BackgroundTaskGroupFriendlyName); group.BackgroundActivated += BackgroundActivity.Start; }
/// <summary> /// Unregister a ServicingCompleteTask. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UnregisterBackgroundTask(object sender, RoutedEventArgs e) { BackgroundTaskSample.UnregisterBackgroundTasks(BackgroundTaskSample.ServicingCompleteTaskName); UpdateUI(); }
/// <summary> /// Unregister a Grouped Background Task. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UnregisterGroupedTask(object sender, RoutedEventArgs e) { BackgroundTaskSample.UnregisterBackgroundTasks(BackgroundTaskSample.GroupedBackgroundTaskName, group); UpdateUI(); }
/// <summary> /// Unregister a TimeTriggeredTask. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UnregisterBackgroundTask(object sender, RoutedEventArgs e) { BackgroundTaskSample.UnregisterBackgroundTasks(BackgroundTaskSample.TimeTriggeredTaskName); UpdateUI(); }
/// <summary> /// Unregister a ApplicationTriggerTask. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UnregisterBackgroundTask(object sender, RoutedEventArgs e) { BackgroundTaskSample.UnregisterBackgroundTasks(BackgroundTaskSample.ApplicationTriggerTaskName); BackgroundTaskSample.ApplicationTriggerTaskResult = ""; UpdateUI(); }
/// <summary> /// Unregister a SampleBackgroundTaskWithCondition. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UnregisterBackgroundTask(object sender, RoutedEventArgs e) { BackgroundTaskSample.UnregisterBackgroundTasks(BackgroundTaskSample.SampleBackgroundTaskWithConditionName); UpdateUI(); }