private void RegisterButton_Click(object sender, RoutedEventArgs e)
        {
            // Create a new background task builder.
            var taskBuilder = new BackgroundTaskBuilder();

            // Create a new NetworkOperatorHotspotAuthentication trigger.
            var trigger = new NetworkOperatorHotspotAuthenticationTrigger();

            // Associate the NetworkOperatorHotspotAuthentication trigger with the background task builder.
            taskBuilder.SetTrigger(trigger);

            // Specify the background task to run when the trigger fires.
            taskBuilder.TaskEntryPoint = ScenarioCommon.BackgroundTaskEntryPoint;

            // Name the background task.
            taskBuilder.Name = ScenarioCommon.BackgroundTaskName;

            try
            {
                // Register the background task.
                var task = taskBuilder.Register();

                // Associate progress and completed event handlers with the new background task.
                task.Completed += ScenarioCommon.Instance.OnBackgroundTaskCompleted;

                UpdateButtonState(true);

                rootPage.NotifyUser("Register was successful", NotifyType.StatusMessage);
            }
            catch (System.Exception ex)
            {
                rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage);
            }
        }
Пример #2
0
        /// <summary>
        /// This is the click handler for the 'Register' button to registers a background task for
        /// the NetworkOperatorHotspotAuthentication event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RegisterButton_Click(object sender, RoutedEventArgs args)
        {
            try
            {
#if WINDOWS_PHONE_APP
                // For windows phone, we need to call RequestAccessAsync always to enable Background Task to be launched even when
                // screen is locked
                BackgroundAccessStatus status = BackgroundExecutionManager.RequestAccessAsync().AsTask().GetAwaiter().GetResult();

                if (status == BackgroundAccessStatus.Denied)
                {
                    rootPage.NotifyUser("Access denied while Requesting Async Access", NotifyType.ErrorMessage);
                    return;
                }
#endif
                // Create a new background task builder.
                var taskBuilder = new BackgroundTaskBuilder();

                // Create a new NetworkOperatorHotspotAuthentication trigger.
                var trigger = new NetworkOperatorHotspotAuthenticationTrigger();

                // Associate the NetworkOperatorHotspotAuthentication trigger with the background task builder.
                taskBuilder.SetTrigger(trigger);

                // Specify the background task to run when the trigger fires.
                taskBuilder.TaskEntryPoint = ScenarioCommon.BackgroundTaskEntryPoint;

                // Name the background task.
                taskBuilder.Name = ScenarioCommon.BackgroundTaskName;

                // Register the background task.
                var task = taskBuilder.Register();

                // Associate progress and completed event handlers with the new background task.
                task.Completed += new BackgroundTaskCompletedEventHandler(ScenarioCommon.Instance.OnBackgroundTaskCompleted);

                UpdateButtonState(true);
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage);
            }
        }