public void Start()
        {
            PeriodicTask periodicTask = new PeriodicTask(Constants.SETTINGS.LIVE_TILE_AGENT);

            WP_to_WP.UI.Services.UiSettings Settings = new WP_to_WP.UI.Services.UiSettings();

            periodicTask.Description = Settings.AppName() + " Task";
            periodicTask.ExpirationTime = System.DateTime.Now.AddDays(10);

            if (Exists())
            {
                ScheduledActionService.Remove(Constants.SETTINGS.LIVE_TILE_AGENT);
            }

            try
            {
                ScheduledActionService.Add(periodicTask);

            #if DEBUG
                ScheduledActionService.LaunchForTest(Constants.SETTINGS.LIVE_TILE_AGENT, TimeSpan.FromSeconds(60));
            #endif

            }
            catch (InvalidOperationException ex)
            {
                if (ex.Message.Contains("BNS Error: The action is disabled"))
                {
                    // MessageBox.Show("Background agents for this application have been disabled by the user.");
                }

            }
        }
Exemple #2
0
        protected override async void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs Args)
        {
            _initialized = false;
            
            var location = await GetLastLocation();

            if (location != null)
            {
                var geocoordinate = new GeoCoordinate(location.Latitude, location.Longitude);
                Map.SetView(geocoordinate, 18, MapAnimationKind.Linear);
            }

            _trackingTask = ScheduledActionService.Find(_TRACKING_TASK_NAME) as PeriodicTask;

            if (_trackingTask != null)
            {
                TrackingButton.DataContext = _trackingTask;
                TrackingEnabled = _trackingTask.IsEnabled;
            }
            else
            {
                TrackingEnabled = false;
            }

            _initialized = true;
        }
Exemple #3
0
        private void LiveTilesButton_Checked(object sender, RoutedEventArgs e)
        {
            if (App.ViewModel.user == null)
            {
                MessageBox.Show("Must be logged in to show followed streams on live tile");
                this.LiveTilesButton.IsChecked = false;
            }

            else
            {
                App.ViewModel.LiveTilesEnabled = true;
                LiveTileHelper.UpdateLiveTile(App.ViewModel.user.Oauth);

                try
                {
                    if (ScheduledActionService.Find(liveTileTaskName) != null)
                    {
                        //if the agent exists, remove and then add it to ensure
                        //the agent's schedule is updated to avoid expiration
                        ScheduledActionService.Remove(liveTileTaskName);
                    }

                    PeriodicTask periodicTask = new PeriodicTask(liveTileTaskName);
                    periodicTask.Description = App.ViewModel.user.Oauth;
                    ScheduledActionService.Add(periodicTask);
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                }
            }
        }
 public void TestCtor()
 {
     var task = new PeriodicTask(42, () => { }, TimeSpan.FromSeconds(1));
     task.Id.Should().Be(42);
     task.IsRemoved.Should().BeFalse();
     task.LastInvocation.Should().Be(DateTime.MinValue);
 }
Exemple #5
0
        private void StartTracking()
        {
            _trackingTask = ScheduledActionService.Find(_TRACKING_TASK_NAME) as PeriodicTask;

            if (_trackingTask != null)
                StopTracking();

            _trackingTask = new PeriodicTask(_TRACKING_TASK_NAME);

            _trackingTask.Description = "Tracks location";

            try
            {
                ScheduledActionService.Add(_trackingTask);

#if DEBUG
                ScheduledActionService.LaunchForTest(_TRACKING_TASK_NAME, TimeSpan.FromSeconds(60));
#endif

                TrackingEnabled = true;
            } 
            catch (Exception ex)
            {
                TrackingButton.IsChecked = false;
                TrackingEnabled = false;
                MessageBox.Show(ex.Message);
            }
        }
 public void Remove()
 {
     PeriodicTask periodicTask = new PeriodicTask(Constants.SETTINGS.LIVE_TILE_AGENT);
     if (ScheduledActionService.Find(periodicTask.Name) != null)
     {
         ScheduledActionService.Remove(Constants.SETTINGS.LIVE_TILE_AGENT);
     }
 }
Exemple #7
0
        private static void RunConnectionCheckTask()
        {
            PeriodicTask periodicTask = new PeriodicTask(
                RepositoryCleaner.CheckClientsConnection, 
                TimeSpan.FromSeconds(5),
                TimeSpan.FromSeconds(30), 
                CancellationToken.None);

            periodicTask.DoPeriodicWorkAsync();
        }       
Exemple #8
0
        private void ButtonBase_OnClick_BackgroundThree(object sender, RoutedEventArgs e)
        {
            _tilePeriodicTask = ScheduledActionService.Find(TileTaskName) as PeriodicTask;

            if (_tilePeriodicTask != null)
            {
                RemoveAgent(TileTaskName);
            }

            StartPeriodicAgent(TileTaskName);
        }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            refreshButton = ApplicationBar.Buttons[0] as ApplicationBarIconButton;
            deleteButton = ApplicationBar.MenuItems[1] as ApplicationBarMenuItem;
            notificationsButton = ApplicationBar.MenuItems[0] as ApplicationBarMenuItem;

            app = (App)Application.Current;

            if (e.NavigationMode == NavigationMode.Back)
            {
                trainingQueueList.SelectedItem = null;
                currentSkillsList.SelectedItem = null;
                app.loadedInfo = null;
                if (curChar == null)
                {
                    await loadLastCharacter();
                }
                return;
            }
            else
            {
                if (app.loadedInfo != null || app.db.characterItems.Count() == 0)
                {
                    this.addCharacterClick(null, null);
                }
                
                string charParam = "";
                if (NavigationContext.QueryString.TryGetValue("char", out charParam))
                {
                    persistSelectedCharacter(charParam);
                }
            }
            await loadLastCharacter();


            const string taskName = "BackgroundTask";
            var oldTask = ScheduledActionService.Find(taskName) as PeriodicTask;
            if (oldTask != null)
            {
                ScheduledActionService.Remove(taskName);
            }
            PeriodicTask task = new PeriodicTask(taskName);
            task.Description = "Background task for character data";
            ScheduledActionService.Add(task);
            //ScheduledActionService.LaunchForTest(taskName, TimeSpan.FromMilliseconds(5000));
        }
        public static void StartTileUpdaterTask()
        {
            PeriodicTask existingTileUpdaterTask = 
                ScheduledActionService.Find(TILE_UPDATER_TASK_NAME) as PeriodicTask;
            if (existingTileUpdaterTask != null)
            {
                try
                {
                    ScheduledActionService.Remove(TILE_UPDATER_TASK_NAME);
                }
                catch (Exception ex)
                {
                    //NOTE: Exceptions during removal are unimportant
                }
            }

            PeriodicTask newTileUpdaterTask = new PeriodicTask(TILE_UPDATER_TASK_NAME)
            {
                Description = "Updates main tile.",
                ExpirationTime = DateTime.Now.AddDays(14),
            };

            try
            {
                ScheduledActionService.Add(newTileUpdaterTask);

#if(DEBUG_AGENT)
				ScheduledActionService.LaunchForTest( TILE_UPDATER_TASK_NAME, TimeSpan.FromSeconds( 30 ) );
#endif
            }
            catch (InvalidOperationException exception)
            {
                if (exception.Message.Contains("BNS Error: The action is disabled"))
                {
                    MessageBox.Show("Background agents for this application have been disabled by the user.");
                }

                if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                {
                    // No user action required. The system prompts the user when the hard limit of periodic tasks has been reached.
                }
            }
            catch (SchedulerServiceException)
            {
                // No user action required.
            }
        }
Exemple #11
0
        public static void StartPeriodicAgent(string Name)
        {

            var periodicTask = ScheduledActionService.Find(Name) as PeriodicTask;

            // If the task already exists and background agents are enabled for the
            // application, you must remove the task and then add it again to update 
            // the schedule
            if (periodicTask != null)
            {
                RemoveAgent(Name);
            }

            periodicTask = new PeriodicTask(Name) { Description = AppResources.TaskDescription };

            try
            {
                ScheduledActionService.Add(periodicTask);

#if DEBUG
                ScheduledActionService.LaunchForTest(Name, TimeSpan.FromSeconds(10));
#endif

            }
            catch (InvalidOperationException exception)
            {

                if (exception.Message.Contains("BNS Error: The action is disabled"))
                {
                }

                if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                {
                }
            }
            catch (SchedulerServiceException)
            {
            }
        }
        public void StartAgent()
        {
            IsAgentEnabled = true;

            var task = ScheduledActionService.Find(TaskName) as PeriodicTask;

            if (task != null)
                RemoveAgent();

            task = new PeriodicTask(TaskName);
            task.Description = CommonResources.BackgroundTaskDescription;

            // Place the call to Add in a try block in case the user has disabled agents.
            try
            {
                ScheduledActionService.Add(task);

                // If debugging is enabled, use LaunchForTest to launch the agent in one minute.
                #if(DEBUG)
                ScheduledActionService.LaunchForTest(TaskName, TimeSpan.FromSeconds(120));
                #endif
            }
            catch (InvalidOperationException exception)
            {
                if (exception.Message.Contains("BNS Error: The action is disabled"))
                {
                    IsAgentEnabled = false;
                }
                if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                {
                    // No user action required. The system prompts the user when the hard limit of periodic tasks has been reached.

                }
            }
            catch (SchedulerServiceException)
            {
                // No user action required.
            }
        }
        public void startBackground()
        {
            pollOut = new PeriodicTask("ScheduledAgent");

            try
            {

                pollOut = ScheduledActionService.Find("PollOut") as PeriodicTask;
                if (pollOut != null)
                    ScheduledActionService.Remove("PollOut");

                pollOut = new PeriodicTask("PollOut");
                pollOut.Description = "waiting to shut down or wake your pc";

                ScheduledActionService.Add(pollOut);

                ScheduledActionService.LaunchForTest("PollOut", TimeSpan.FromSeconds(10));

            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
        private void InitializeAgentNotification()
        {
            // Obtain a reference to the period task, if one exists
            notificationTask = ScheduledActionService.Find(notificationTaskName) as PeriodicTask;

            if (notificationTask != null)
                ScheduledActionService.Remove(notificationTaskName);

            notificationTask = new PeriodicTask(notificationTaskName);

            // The description is required for periodic agents. This is the string that the user
            // will see in the background services Settings page on the device.
            notificationTask.Description = "This demonstrates a periodic task.";


            // Place the call to Add in a try block in case the user has disabled agents.
            try
            {
                //ScheduledActionService.Add(notificationTask);

                // If debugging is enabled, use LaunchForTest to launch the agent in one minute.
#if(DEBUG_AGENT)
                //ScheduledActionService.LaunchForTest(notificationTaskName, TimeSpan.FromSeconds(10));
#endif
            }
            catch (InvalidOperationException exception)
            {
                if (exception.Message.Contains("BNS Error: The action is disabled"))
                {
                    MessageBox.Show("Background agents for this application have been disabled by the user.");
                }

                if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                {
                    // No user action required. The system prompts the user when the hard limit of periodic tasks has been reached.

                }

            }
            catch (SchedulerServiceException)
            {
                // No user action required.  
            }
 
        }
        public void StartPeriodicAgent()
        {
            // is old tasks are running, remove them
            foreach (PeriodicTask pt in ScheduledActionService.GetActions<PeriodicTask>())
            {
                ScheduledActionService.Remove(pt.Name);
            }
            // create a new task
            _periodicTask = new PeriodicTask(PeriodicTaskName)
            {
                Description = "This is the Fuel application update agent.",
                ExpirationTime = DateTime.Now.AddDays(14)
            };
            // load description from localized strings
            // set expiration days
            try
            {
                // add thas to scheduled action service
                ScheduledActionService.Add(_periodicTask);
                // debug, so run in every 10 secs
#if(DEBUG)
                ScheduledActionService.LaunchForTest(PeriodicTaskName, TimeSpan.FromSeconds(10));
                System.Diagnostics.Debug.WriteLine("Periodic task is started: " + _periodicTask);
#endif

            }
            catch (InvalidOperationException exception)
            {
                if (exception.Message.Contains("BNS Error: The action is disabled"))
                {
#if(DEBUG)
                    System.Diagnostics.Debug.WriteLine("BNS Error: The action is disabled");
#endif
                    // load error text from localized strings
                }
                if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                {
#if(DEBUG)
                    System.Diagnostics.Debug.WriteLine("BNS Error: The maximum number of ScheduledActions of this type have already been added.");
#endif
                    // No user action required. The system prompts the user when the hard limit of periodic tasks has been reached.
                }
            }
            catch (SchedulerServiceException)
            {
                // No user action required.
            }
            //update tile right now
            Tools.Tools.UpdateLiveTile();
        }
 private void TaskAgentSwitch_Checked(object sender, RoutedEventArgs e)
 {
     try
     {
         var updateScheduledTask = ScheduledActionService.Find(agentName) as PeriodicTask;
         if (updateScheduledTask != null)
             ScheduledActionService.Remove(agentName);
         updateScheduledTask = new PeriodicTask(agentName);
         updateScheduledTask.Description = "开启后新番提醒会定时检查您的订阅是否有更新,如果有更新将第一时间通知您";
         ScheduledActionService.Add(updateScheduledTask);
         if (settings.Contains("LastUpdatedTime"))
             settings.Remove("LastUpdatedTime");
         settings.Add("LastUpdatedTime", DateTime.Now);
         if (!settings.Contains("UpdateInterval"))
             settings.Add("UpdateInterval", 0);
         settings.Save();
         ListPicker.IsEnabled = true;
         SetLockscreenButton.IsEnabled = true;
         if (Debugger.IsAttached)
         {
             ScheduledActionService.LaunchForTest(agentName, TimeSpan.FromSeconds(30));
         }
     }
     catch (InvalidOperationException exception)
     {
         if (exception.Message.Contains("BNS Error: The action is disabled"))
         {
             MessageBox.Show("本程序的后台任务被禁用,无法后台检查订阅更新,请从 系统设置-应用程序-后台任务 中开启本程序的后台任务后重试", "错误", MessageBoxButton.OK);
         }
         if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
         {
             MessageBox.Show("手机的后台任务数量已经达到上限,请从 系统设置-应用程序-后台任务 中关闭不需要的其它程序的后台任务后重试", "错误", MessageBoxButton.OK);
         }
         TaskAgentSwitch.IsChecked = false;
     }
     catch (SchedulerServiceException)
     {
         MessageBox.Show("启动后台任务失败", "错误", MessageBoxButton.OK);
         TaskAgentSwitch.IsChecked = false;
     }
 }
Exemple #17
0
        private void LiveTilesButton_Unchecked(object sender, RoutedEventArgs e)
        {
            App.ViewModel.LiveTilesEnabled = false;

            try
            {
                if (ScheduledActionService.Find(liveTileTaskName) != null)
                {
                    //if the agent exists, remove and then add it to ensure
                    //the agent's schedule is updated to avoid expiration
                    ScheduledActionService.Remove(liveTileTaskName);
                }

                PeriodicTask periodicTask = new PeriodicTask(liveTileTaskName);
                periodicTask.Description = "No OAuth to use";
                ScheduledActionService.Add(periodicTask);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
        private async void LockHelper(Uri backgroundImageUri, string backgroundAction)
        {
            try
            {
                switch (backgroundAction)
                {
                    case "allow":
                        {
                            await LockScreenManager.RequestAccessAsync();
                            _isLockScreenProvider = LockScreenManager.IsProvidedByCurrentApplication;
                            if (_isLockScreenProvider)
                            {
                                
                            }
                            else MessageBox.Show("You said no, so I can't update your lock screen.");
                        }
                        break;
                    case "set":
                    case "pick":
                    case "reset":
                        {
                            await LockScreenManager.RequestAccessAsync();
                            _isLockScreenProvider = LockScreenManager.IsProvidedByCurrentApplication;
                            if (_isLockScreenProvider)
                            {
                                LockScreen.SetImageUri(backgroundImageUri);
                                Console.WriteLine("New current image set to {0}", backgroundImageUri);
                            }
                            else
                            {
                                MessageBox.Show("You said no, so I can't update your lock screen.");
                            }

                            // Obtain a reference to the period task, if one exists
                            _periodicTask = ScheduledActionService.Find(PeriodicTaskName) as PeriodicTask;

                            // If the task already exists and background agents are enabled for the
                            // application, you must remove the task and then add it again to update 
                            // the schedule
                            if (_periodicTask != null)
                            {
                                RemoveAgent(PeriodicTaskName);
                            }

                            // Variable for tracking enabled status of background agents for this app.
                        }
                        break;
                    case "check":
                        {
                            _isLockScreenProvider = LockScreenManager.IsProvidedByCurrentApplication;
                        }
                        break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
        // Load data for the ViewModel Items
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (!App.ViewModel.IsDataLoaded)
            {
                App.ViewModel.LoadData(dailyForecastData);
            }

            if (IsolatedStorageSettings.ApplicationSettings.Contains("EnableLocation"))
            {
                //User already gave us his agreement for using his position
                if ((bool)IsolatedStorageSettings.ApplicationSettings["EnableLocation"] == true)

                    return;
                //If he didn't we ask for it
                else
                {
                    MessageBoxResult result =
                                MessageBox.Show("Can Weatherish use your position? you can change it later in app settings",
                                "Location",
                                MessageBoxButton.OKCancel);

                    if (result == MessageBoxResult.OK)
                    {
                        IsolatedStorageSettings.ApplicationSettings["EnableLocation"] = true;
                    }
                    else
                    {
                        IsolatedStorageSettings.ApplicationSettings["EnableLocation"] = false;
                    }

                    IsolatedStorageSettings.ApplicationSettings.Save();
                }
            }

                //Ask for user agreement in using his position
            else
            {
                MessageBoxResult result =
                                MessageBox.Show("Can Weatherish use your position?, you can change it later in app settings",
                            "Location",
                            MessageBoxButton.OKCancel);

                if (result == MessageBoxResult.OK)
                {
                    IsolatedStorageSettings.ApplicationSettings["EnableLocation"] = true;
                }
                else
                {
                    IsolatedStorageSettings.ApplicationSettings["EnableLocation"] = false;
                }

                IsolatedStorageSettings.ApplicationSettings.Save();
            }
            periodicTask = ScheduledActionService.Find(periodicTaskName) as PeriodicTask;

        }
        public void StartPeriodicAgent()
        {
            // Variable for tracking enabled status of background agents for this app.
            agentsAreEnabled = true;

            // Obtain a reference to the period task, if one exists
            periodicTask = ScheduledActionService.Find(periodicTaskName) as PeriodicTask;

            // If the task already exists and background agents are enabled for the
            // application, you must remove the task and then add it again to update 
            // the schedule
            if (periodicTask != null)
            {
                RemoveAgent(periodicTaskName);
            }

            periodicTask = new PeriodicTask(periodicTaskName);

            // The description is required for periodic agents. This is the string that the user
            // will see in the background services Settings page on the device.
            periodicTask.Description = "Weatherish Lockscreen and Tile task";

            // Place the call to Add in a try block in case the user has disabled agents.
            try
            {
                ScheduledActionService.Add(periodicTask);
            }
            catch (InvalidOperationException exception)
            {
                if (exception.Message.Contains("BNS Error: The action is disabled"))
                {
                    MessageBox.Show("Background agents for this application have been disabled by the user.");
                    agentsAreEnabled = false;
                }

                if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                {
                    // No user action required. The system prompts the user when the hard limit of periodic tasks has been reached.

                }
            }
            catch (SchedulerServiceException)
            {
                // No user action required.
            }
        }
        /// <summary>
        /// Runs schedule agent for notification
        /// </summary>
        private void StartPeriodicAgent()
        {
            // is old task running, remove it
            smartPeriodicTask = ScheduledActionService.Find(socrataPeriodicTaskName) as PeriodicTask;
            if (smartPeriodicTask != null)
            {
                try
                {
                    ScheduledActionService.Remove(socrataPeriodicTaskName);
                }
                catch (Exception)
                {
                }
            }
            // create a new task
            smartPeriodicTask = new PeriodicTask(socrataPeriodicTaskName);
            // load description from localized strings
            smartPeriodicTask.Description = socrataPeriodicTaskDescription;
            // set expiration days
            smartPeriodicTask.ExpirationTime = DateTime.Now.AddDays(14);
            try
            {
                // add this to scheduled action service
                ScheduledActionService.Add(smartPeriodicTask);
                // debug, so run in every 30 secs
#if(DEBUG_AGENT)
                ScheduledActionService.LaunchForTest(socrataPeriodicTaskName, TimeSpan.FromSeconds(30));
                System.Diagnostics.Debug.WriteLine("Periodic task is started: " + socrataPeriodicTaskName);
#endif
            }
            catch (InvalidOperationException exception)
            {
                if (exception.Message.Contains("BNS Error: The action is disabled"))
                {
                    // load error text from localized strings
                    MessageBox.Show("Background agents for this application have been disabled by the user.");
                }
                if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                {
                    // No user action required. The system prompts the user when the hard limit of periodic tasks has been reached.
                }
            }
            catch (SchedulerServiceException)
            {
                // No user action required.
            }
        }
Exemple #22
0
        private void StartPeriodicAgent(string taskName)
        {
            // Obtain a reference to the period task, if one exists
            var toastPeriodicTask = ScheduledActionService.Find(taskName) as PeriodicTask;
            //ScheduledActionService.Add(toastPeriodicTask);
            // If the task already exists and background agent is enabled for the
            // app, remove the task and then add it again to update 
            // the schedule.
            if (toastPeriodicTask != null)
            {
                RemoveAgent(taskName);
            }
            toastPeriodicTask = new PeriodicTask(taskName);

            // The description is required for periodic agents. This is the string that the user
            // will see in the background services Settings page on the phone.
            toastPeriodicTask.Description = "Testje";

            // Place the call to add a periodic agent. This call must be placed in 
            // a try block in case the user has disabled agents.
            try
            {
                ScheduledActionService.Add(toastPeriodicTask);


                // If debugging is enabled, use LaunchForTest to launch the agent in one minute.
#if(DEBUG)
                ScheduledActionService.LaunchForTest(taskName, TimeSpan.FromSeconds(60));
#endif
            }
            catch (InvalidOperationException exception)
            {
                if (exception.Message.Contains("BNS Error: The action is disabled"))
                {
                    MessageBox.Show("Background agents for this application have been disabled by the user.");
                }
                else if (
                    exception.Message.Contains(
                        "BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                {
                    // No user action required. The system prompts the user when the hard limit of periodic tasks has been reached.
                    MessageBox.Show(
                        "BNS Error: The maximum number of ScheduledActions of this type have already been added.");
                }
                else
                {
                    MessageBox.Show("An InvalidOperationException occurred.");
                }
            }
            catch (SchedulerServiceException)
            {
                // No user action required.
            }
            finally
            {
                // Determine if there is a running periodic agent and update the UI.
                toastPeriodicTask = ScheduledActionService.Find(taskName) as PeriodicTask;
                if (toastPeriodicTask != null)
                {
                    //
                }
            }
        }
Exemple #23
0
        private void StartPeriodicAgent()
        {
            
            // Obtain a reference to the periodic task, if one exists
            periodicTask = ScheduledActionService.Find(periodicTaskName) as PeriodicTask;

            // If Task already exists and background agents are enabled for the application
            // you must remove the task and then add it again to update the schedule
            if (periodicTask != null)
            {
                RemoveAgent(periodicTaskName);
            }

            periodicTask = new PeriodicTask(periodicTaskName);

            // The description is required for periodic agents. This is the string that the user will 
            // see in the background services Settings page on the device
            periodicTask.Description = "WebApp Background service to update live tiles";

            try
            {
                ScheduledActionService.Add(periodicTask);
                ScheduledActionService.LaunchForTest(periodicTaskName, TimeSpan.FromSeconds(10));
            }
            catch (InvalidOperationException exception)
            {
                if (exception.Message.Contains("BNS Error: The action is disabled"))
                {
                    MessageBox.Show("Background agents for this application have been disabled");
                }

                if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                {
                }
            }
            catch (SchedulerServiceException)
            {
            }
            catch (Exception exn)
            {
                Debug.WriteLine(exn.ToString());
            }
        }