private BackgroundTaskRegistration RegisterTask( Type taskType, IBackgroundTrigger trigger, SystemConditionType systemConditionType = SystemConditionType.Invalid) { var builder = new BackgroundTaskBuilder(); /// A string identifier for the background task. builder.Name = taskType.Name; /// The entry point of the task. /// This HAS to be the full name of the background task: {Namespace}.{Class name} builder.TaskEntryPoint = taskType.FullName; /// The specific trigger event that will fire the task on our application. builder.SetTrigger(trigger); /// A condition for the task to run. /// If specified, after the event trigger is fired, the OS will wait for /// the condition situation to happen before executing the task. if (systemConditionType != SystemConditionType.Invalid) { builder.AddCondition(new SystemCondition(systemConditionType)); } /// Register the task and returns the registration output. return(builder.Register()); }
private void RegisterBackgroundTask(object sender, RoutedEventArgs e) { /* * * // wake from sleep - works when press side button and lid is closed * //wake from hibernate - works when press side button and lid is closed * * var trigger = SystemTriggerType.UserPresent; * var condition = SystemConditionType.SessionConnected;*/ var trigger = SystemTriggerType.UserPresent; SystemConditionType condition = SystemConditionType.SessionConnected; BackgroundTaskSample.UnregisterBackgroundTasks(BackgroundTaskSample.SampleBackgroundTaskName); var task = BackgroundTaskSample.RegisterBackgroundTask(BackgroundTaskSample.SampleBackgroundTaskEntryPoint, BackgroundTaskSample.SampleBackgroundTaskName, new SystemTrigger(trigger, false), new SystemCondition(condition)); if (task != null) { TextBlock.Text = $"Bg task registered: Trigger: {trigger}, Condition: {condition}"; } }
public SystemCondition(SystemConditionType conditionType) { ConditionType = conditionType; }