Inheritance: INetworkOperatorHotspotAuthenticationTrigger, IBackgroundTrigger
Exemple #1
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
            {
                // 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);
            }
        }
        /// <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);
            }
        }