Inheritance: IMaintenanceTrigger, IBackgroundTrigger
        private void RegisterTaskButton_Click(Object sender, RoutedEventArgs e)
        {
            if (GetRegisteredTask() == null)
            {
                BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();
                MaintenanceTrigger trigger = new MaintenanceTrigger(MAINTENANCE_INTERVAL, false);
                taskBuilder.SetTrigger(trigger);
                taskBuilder.TaskEntryPoint = PUSH_NOTIFICATIONS_TASK_ENTRY_POINT;
                taskBuilder.Name = PUSH_NOTIFICATIONS_TASK_NAME;

                SystemCondition internetCondition = new SystemCondition(SystemConditionType.InternetAvailable);
                taskBuilder.AddCondition(internetCondition);

                try
                {
                    taskBuilder.Register();
                    rootPage.NotifyUser("Task registered", NotifyType.StatusMessage);
                }
                catch (Exception ex)
                {
                    rootPage.NotifyUser("Error registering task: " + ex.Message, NotifyType.ErrorMessage);
                }
            }
            else
            {
                rootPage.NotifyUser("Task already registered", NotifyType.ErrorMessage);
            }
        }
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {
            var taskEntryPoint = "BackGroundUpdater.BackGroundRunner";
            var taskName = "BackGroundRunner";
            MaintenanceTrigger taskTrigger = new MaintenanceTrigger(15, false);

            var task = RegisterBackgroundTask(taskEntryPoint, taskName, taskTrigger, null);
            task.Progress += new BackgroundTaskProgressEventHandler(OnProgress);
            task.Completed += new BackgroundTaskCompletedEventHandler(OnCompleted);
        }
        /// <summary>
        /// Register the background task
        /// </summary>
        public async Task RegisterAsync()
        {
            BackgroundAccessStatus status = BackgroundExecutionManager.GetAccessStatus();

            if (status == BackgroundAccessStatus.Unspecified)
            {
                BackgroundAccessStatus backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync();

                if (backgroundAccessStatus != BackgroundAccessStatus.Denied)
                {
                    // Delete all tasks
                    foreach (var registeredTask in BackgroundTaskRegistration.AllTasks)
                    {
                        registeredTask.Value.Unregister(true);
                    }

                    // Register new tasks
                    foreach (var task in _tasks)
                    {
                        BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder
                        {
                            Name = task.Key,
                            TaskEntryPoint = task.Value
                        };

                        IBackgroundTrigger trigger;

                        if (backgroundAccessStatus == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity ||
                            backgroundAccessStatus == BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity)
                        {
                            trigger = new TimeTrigger(30, false);
                        }
                        else
                        {
                            trigger = new MaintenanceTrigger(30, false);
                        }

                        taskBuilder.SetTrigger(trigger);
                        taskBuilder.Register();
                    }
                }
            }
        }
        private const int MAINTENANCE_INTERVAL = 10 * 24 * 60; // Check for channels that need to be updated every 10 days

		public App()
		{
			InitializeComponent();
			this.Suspending += new SuspendingEventHandler(OnSuspending);

            if (!IsTaskRegistered())
            {
                BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();
                MaintenanceTrigger trigger = new MaintenanceTrigger(MAINTENANCE_INTERVAL, false);
                taskBuilder.SetTrigger(trigger);
                taskBuilder.TaskEntryPoint = PUSH_NOTIFICATIONS_TASK_ENTRY_POINT;
                taskBuilder.Name = PUSH_NOTIFICATIONS_TASK_NAME;

                SystemCondition internetCondition = new SystemCondition(SystemConditionType.InternetAvailable);
                taskBuilder.AddCondition(internetCondition);

                taskBuilder.Register();
            }
		}
        private async void RegisterBackgroundTask()
        {
            var taskRegisterd = false;
            var taskName = "BackgroundAgent1";
            var entryPoint = "BackgroundAgent.Trigger";
            foreach(var task in BackgroundTaskRegistration.AllTasks)
            {
                if(task.Value.Name == taskName)
                {
                    taskRegisterd = true;
                    task.Value.Unregister(true);
                    break;
                }
            }

            taskRegisterd = false;
            if(!taskRegisterd)
            {
                var builder = new BackgroundTaskBuilder();

                builder.Name = taskName;
                builder.TaskEntryPoint = entryPoint;
                var mtrigger = new MaintenanceTrigger(16, false);
                builder.SetTrigger(mtrigger);

                var status = await BackgroundExecutionManager.RequestAccessAsync();
                switch(status)
                {
                    case BackgroundAccessStatus.Unspecified:
                        
                    case BackgroundAccessStatus.Denied:
                                            Debug.WriteLine("Access Denied!");
                        break;

                    default:
                        Debug.WriteLine("F*****g Unregister Task Idiot!");
                        break;
                }
                BackgroundTaskRegistration task = builder.Register();
                var msgbox = new MessageDialog("Background Task Registered");
                await msgbox.ShowAsync();
            }
        
            UpdateLayout();
        }