当前位置: 首页>>代码示例>>C#>>正文


C# IBackgroundTaskRegistration类代码示例

本文整理汇总了C#中IBackgroundTaskRegistration的典型用法代码示例。如果您正苦于以下问题:C# IBackgroundTaskRegistration类的具体用法?C# IBackgroundTaskRegistration怎么用?C# IBackgroundTaskRegistration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IBackgroundTaskRegistration类属于命名空间,在下文中一共展示了IBackgroundTaskRegistration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnCompleted

 private void OnCompleted(IBackgroundTaskRegistration task, BackgroundTaskCompletedEventArgs args)
 {
     ShellToast toast = new ShellToast();
     toast.Title = "Sample Application";
     toast.Content = "Background Task Complete";
     toast.Show();
 }
开发者ID:vinayganesh,项目名称:Wp8.1BackgroundTask,代码行数:7,代码来源:RegisterBackgroundTask.cs

示例2: OnProgress

 /// <summary>
 /// Handle background task progress.
 /// </summary>
 /// <param name="task">The task that is reporting progress.</param>
 /// <param name="e">Arguments of the progress report.</param>
 private void OnProgress(IBackgroundTaskRegistration task, BackgroundTaskProgressEventArgs args)
 {
     var ignored = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         var progress = "Progress: " + args.Progress + "%";
         BackgroundTaskSample.ServicingCompleteTaskProgress = progress;
         UpdateUI();
     });
 }
开发者ID:huoxudong125,项目名称:Windows-universal-samples,代码行数:14,代码来源:Scenario3_ServicingCompleteTask.xaml.cs

示例3: AttachProgressAndCompletedHandlers

 /// <summary>
 /// Attach progress and completed handers to a background task.
 /// </summary>
 /// <param name="task">The task to attach progress and completed handlers to.</param>
 private void AttachProgressAndCompletedHandlers(IBackgroundTaskRegistration task)
 {
     task.Progress += new BackgroundTaskProgressEventHandler(OnProgress);
     task.Completed += new BackgroundTaskCompletedEventHandler(OnCompleted);
 }
开发者ID:huoxudong125,项目名称:Windows-universal-samples,代码行数:9,代码来源:Scenario3_ServicingCompleteTask.xaml.cs

示例4: OnCompleted

 /// <summary>
 /// Handle background task completion.
 /// </summary>
 /// <param name="task">The task that is reporting completion.</param>
 /// <param name="e">Arguments of the completion report.</param>
 private void OnCompleted(IBackgroundTaskRegistration task, BackgroundTaskCompletedEventArgs args)
 {
     UpdateUI();
 }
开发者ID:huoxudong125,项目名称:Windows-universal-samples,代码行数:9,代码来源:Scenario3_ServicingCompleteTask.xaml.cs

示例5: OnNavigatedTo

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        ///
        /// We will enable/disable parts of the UI if the device doesn't support it.
        /// </summary>
        /// <param name="eventArgs">Event data that describes how this page was reached. The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            rootPage = MainPage.Current;

            // Get the existing task if already registered
            if (taskRegistration == null)
            {
                // Find the task if we previously registered it
                foreach (var task in BackgroundTaskRegistration.AllTasks.Values)
                {
                    if (task.Name == taskName)
                    {
                        taskRegistration = task;
                        taskRegistration.Completed += OnBackgroundTaskCompleted;
                        break;
                    }
                }
            }
            else
                taskRegistration.Completed += OnBackgroundTaskCompleted;

            // Attach handlers for suspension to stop the watcher when the App is suspended.
            App.Current.Suspending += App_Suspending;
            App.Current.Resuming += App_Resuming;

            rootPage.NotifyUser("Press Run to register watcher.", NotifyType.StatusMessage);
        }
开发者ID:henkhouwaard,项目名称:Windows-universal-samples,代码行数:34,代码来源:Scenario5_AggregatingWatcher.xaml.cs

示例6: StartLocationTracker

    public void StartLocationTracker()
    {
     if( CanRunAsTask() )
      {
        BackgroundTaskBuilder geolocTaskBuilder = new BackgroundTaskBuilder();

        geolocTaskBuilder.Name = SampleBackgroundTaskName;
        geolocTaskBuilder.TaskEntryPoint = SampleBackgroundTaskEntryPoint;

        // Create a new timer triggering at a 15 minute interval
        var trigger = new TimeTrigger( UpdateInterval, true );

        // Associate the timer trigger with the background task builder
        geolocTaskBuilder.SetTrigger( trigger );

        // Register the background task
        _geolocTask = geolocTaskBuilder.Register();

        // Associate an event handler with the new background task
        _geolocTask.Completed += new BackgroundTaskCompletedEventHandler( OnCompleted );
      }
      else
      {
         task = new LocationBackgroundTask();
        timer = ThreadPoolTimer.CreatePeriodicTimer( TimerElapsed, new TimeSpan( TimeSpan.TicksPerMillisecond * 30000 ) );
     }
    }
开发者ID:Georotzen,项目名称:.NET-SDK-1,代码行数:27,代码来源:Win8LocationTrackerEngine.cs

示例7: UnregisterTask

 void UnregisterTask()
 {
     this.taskRegistration.Completed -= OnCompleted;
     this.taskRegistration.Progress -= OnProgress;
     this.taskRegistration.Unregister(false);
     this.taskRegistration = null;
     BackgroundExecutionManager.RemoveAccess();
 }
开发者ID:modulexcite,项目名称:TrainingContent,代码行数:8,代码来源:MainPage.xaml.cs

示例8: StopLocationTracker

 public void StopLocationTracker()
 {
   if( null != _geolocTask )
   {
     _geolocTask.Unregister( true );
     _geolocTask = null;
   }
 }
开发者ID:Georotzen,项目名称:.NET-SDK-1,代码行数:8,代码来源:Win8LocationTrackerEngine.cs

示例9: RunInUiThreadIdleAsync

		private async Task<Tuple<bool, string>> TryRegisterUploadToOneDriveBackgroundTaskAsync()
		{
			bool isOk = false;
			string msg = string.Empty;

			string errorMsg = string.Empty;
			BackgroundAccessStatus backgroundAccessStatus = BackgroundAccessStatus.Unspecified;

			_uploadToOneDriveBkgTaskReg = null;
			UnregisterTaskIfAlreadyRegistered(); // I need to unregister and register anew coz I need to obtain the trigger

			try
			{
				// Get permission for a background task from the user. If the user has already answered once,
				// this does nothing and the user must manually update their preference via PC Settings.
				Task<BackgroundAccessStatus> requestAccess = null;
				await RunInUiThreadIdleAsync(() => requestAccess = BackgroundExecutionManager.RequestAccessAsync().AsTask()).ConfigureAwait(false);
				backgroundAccessStatus = await requestAccess.ConfigureAwait(false);

				// Regardless of the answer, register the background task. If the user later adds this application
				// to the lock screen, the background task will be ready to run.
				// Create a new background task builder
				BackgroundTaskBuilder bkgTaskBuilder = new BackgroundTaskBuilder
				{
					Name = ConstantData.ODU_BACKGROUND_TASK_NAME,
					TaskEntryPoint = ConstantData.ODU_BACKGROUND_TASK_ENTRY_POINT
				};

				_uploadToOneDriveTrigger = new ApplicationTrigger();
				bkgTaskBuilder.SetTrigger(_uploadToOneDriveTrigger);
				// bkgTaskBuilder.AddCondition(new SystemCondition(SystemConditionType.SessionDisconnected)); // NO!
				// Register the background task
				_uploadToOneDriveBkgTaskReg = bkgTaskBuilder.Register();
			}
			catch (Exception ex)
			{
				errorMsg = ex.ToString();
				backgroundAccessStatus = BackgroundAccessStatus.Denied;
				Logger.Add_TPL(ex.ToString(), Logger.ForegroundLogFilename);
			}

			switch (backgroundAccessStatus)
			{
				case BackgroundAccessStatus.Unspecified:
					msg = "Cannot run in background, enable it in the \"Battery Saver\" app";
					break;
				case BackgroundAccessStatus.Denied:
					msg = string.IsNullOrWhiteSpace(errorMsg) ? "Cannot run in background, enable it in Settings - Privacy - Background apps" : errorMsg;
					break;
				default:
					msg = "Background task on";
					isOk = true;
					break;
			}

			return Tuple.Create(isOk, msg);
		}
开发者ID:lolluslollus,项目名称:UniFiler10,代码行数:57,代码来源:BackgroundTaskHelper.cs

示例10: OnNavigatedTo

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached. The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // Loop through all background tasks to see if SampleBackgroundTaskName is already registered
            foreach (var cur in BackgroundTaskRegistration.AllTasks)
            {
                if (cur.Value.Name == SampleBackgroundTaskName)
                {
                    _geolocTask = cur.Value;
                    break;
                }
            }

            if (_geolocTask != null)
            {
                // Associate an event handler with the existing background task
                _geolocTask.Completed += new BackgroundTaskCompletedEventHandler(OnCompleted);

                try
                {
                    BackgroundAccessStatus backgroundAccessStatus = BackgroundExecutionManager.GetAccessStatus();

                    switch (backgroundAccessStatus)
                    {
                        case BackgroundAccessStatus.Unspecified:
                        case BackgroundAccessStatus.Denied:
                            rootPage.NotifyUser("This application must be added to the lock screen before the background task will run.", NotifyType.ErrorMessage);
                            break;

                        default:
                            rootPage.NotifyUser("Background task is already registered. Waiting for next update...", NotifyType.ErrorMessage);
                            break;
                    }
                }
                catch (Exception ex)
                {
                    // HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED) == 0x80070032
                    const int RequestNotSupportedHResult = unchecked((int)0x80070032);

                    if (ex.HResult == RequestNotSupportedHResult)
                    {
                        rootPage.NotifyUser("Location Simulator not supported.  Could not determine lock screen status, be sure that the application is added to the lock screen.", NotifyType.StatusMessage);
                    }
                    else
                    {
                        rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage);
                    }
                }

                UpdateButtonStates(/*registered:*/ true);
            }
            else
            {
                UpdateButtonStates(/*registered:*/ false);
            }
        }
开发者ID:mbin,项目名称:Win81App,代码行数:60,代码来源:Scenario3_BackgroundTask.xaml.cs

示例11: MainPage

        public MainPage()
        {
            this.InitializeComponent();
            
            beacons = new ObservableCollection<iBeaconData>();
            this.DataContext = beacons;

            //Unregister the old task
            var taskAdvertisementWatcher = BackgroundTaskRegistration.AllTasks.Values.Where(t => t.Name == taskName).FirstOrDefault();
            if (taskAdvertisementWatcher != null)
            {
                taskAdvertisementWatcher.Unregister(true);
                taskAdvertisementWatcher = null;
                Button_Click(null, null);
            }
        }
开发者ID:danardelean,项目名称:Beacons.Universal,代码行数:16,代码来源:MainPage.xaml.cs

示例12: OnNavigatedTo

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached. The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // Loop through all background tasks to see if SampleGeofenceBackgroundTask is already registered
            foreach (var cur in BackgroundTaskRegistration.AllTasks)
            {
                if (cur.Value.Name == SampleBackgroundTaskName)
                {
                    _geofenceTask = cur.Value;
                    break;
                }
            }

            if (_geofenceTask != null)
            {
                FillEventListBoxWithExistingEvents();

                // Associate an event handler with the existing background task
                _geofenceTask.Completed += OnCompleted;

                try
                {
                    BackgroundAccessStatus backgroundAccessStatus = BackgroundExecutionManager.GetAccessStatus();
                    switch (backgroundAccessStatus)
                    {
                        case BackgroundAccessStatus.Unspecified:
                        case BackgroundAccessStatus.Denied:
                            _rootPage.NotifyUser("Not able to run in background. Application must be added to the lock screen.", NotifyType.ErrorMessage);
                            break;

                        default:
                            _rootPage.NotifyUser("Background task is already registered. Waiting for next update...", NotifyType.StatusMessage);
                            break;
                    }
                }
                catch (Exception ex)
                {
                    _rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage);
                }
                UpdateButtonStates(/*registered:*/ true);
            }
            else
            {
                UpdateButtonStates(/*registered:*/ false);
            }
        }
开发者ID:RasmusTG,项目名称:Windows-universal-samples,代码行数:50,代码来源:Scenario5_GeofenceBackgroundTask.xaml.cs

示例13: UpdateTask

        void UpdateTask()
        {
            lock (lockable)
            {
                var task = FindTask();

                if (task == backgroundTaskRegistration)
                    return;

                if (backgroundTaskRegistration != null)
                    backgroundTaskRegistration.Completed -= OnCompleted;

                backgroundTaskRegistration = task;

                if (backgroundTaskRegistration != null)
                    backgroundTaskRegistration.Completed += OnCompleted;
            }
        }
开发者ID:fengweijp,项目名称:Win2D,代码行数:18,代码来源:LiveTileUpdater.cs

示例14: OnNavigatedTo

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            rootPage = MainPage.Current;
            try
            {
                foreach (var current in BackgroundTaskRegistration.AllTasks)
                {
                    if (current.Value.Name == "SocketActivityBackgroundTask")
                    {
                        task = current.Value;
                        break;
                    }
                }

                // If there is no task allready created, create a new one
                if (task == null)
                {
                    var socketTaskBuilder = new BackgroundTaskBuilder();
                    socketTaskBuilder.Name = "SocketActivityBackgroundTask";
                    socketTaskBuilder.TaskEntryPoint = "SocketActivityBackgroundTask.SocketActivityTask";
                    var trigger = new SocketActivityTrigger();
                    socketTaskBuilder.SetTrigger(trigger);
                    task = socketTaskBuilder.Register();
                }

                SocketActivityInformation socketInformation;
                if (SocketActivityInformation.AllSockets.TryGetValue(socketId, out socketInformation))
                {
                    // Application can take ownership of the socket and make any socket operation
                    // For sample it is just transfering it back.
                    socket = socketInformation.StreamSocket;
                    socket.TransferOwnership(socketId);
                    socket = null;
                    rootPage.NotifyUser("Connected. You may close the application", NotifyType.StatusMessage);
                    TargetServerTextBox.IsEnabled = false;
                    ConnectButton.IsEnabled = false;
                }

            }
            catch (Exception exception)
            {
                rootPage.NotifyUser(exception.Message, NotifyType.ErrorMessage);
            }
        }
开发者ID:C-C-D-I,项目名称:Windows-universal-samples,代码行数:44,代码来源:Scenario1_Connect.xaml.cs

示例15: SetupBackGroundTask

        private void SetupBackGroundTask()
        {
            foreach(var task in BackgroundTaskRegistration.AllTasks)
            {
                if(task.Value.Name == BackgroundTaskName)
                {
                    regTask = task.Value;
                }
            }

            if(regTask != null)
            {
                regTask.Completed += RegTask_Completed;
            }

            else
            {
                RegisterTask();
            }
        }
开发者ID:KristofColpaert,项目名称:nmct.WindowsDevelopment,代码行数:20,代码来源:MainPage.xaml.cs


注:本文中的IBackgroundTaskRegistration类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。