• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# IBackgroundTaskRegistration类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



IBackgroundTaskRegistration类属于命名空间,在下文中一共展示了IBackgroundTaskRegistration类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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 progress = "Progress: " + args.Progress + "%";
     BackgroundTaskSample.SampleBackgroundTaskWithConditionProgress = progress;
     UpdateUI();
 }
开发者ID:t-angma,项目名称:Windows-universal-samples,代码行数:11,代码来源:scenario2_samplebackgroundtaskwithcondition.xaml.cs


示例6: UnregisterBackgroundTask

 private void UnregisterBackgroundTask(IBackgroundTaskRegistration taskReg)
 {
     taskReg.Unregister(true);
     ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
     settings.Values["eventCount"] = (uint)0;
 }
开发者ID:RasmusTG,项目名称:Windows-universal-samples,代码行数:6,代码来源:Scenario3_BackgroundDeviceWatcher.xaml.cs


示例7: 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 async void OnCompleted(IBackgroundTaskRegistration task, BackgroundTaskCompletedEventArgs args)
        {
            ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;

            Object profile = localSettings.Values["InternetProfile"];
            Object adapter = localSettings.Values["NetworkAdapterId"];

            Object hasNewConnectionCost = localSettings.Values["HasNewConnectionCost"];
            Object hasNewDomainConnectivityLevel = localSettings.Values["HasNewDomainConnectivityLevel"];
            Object hasNewHostNameList = localSettings.Values["HasNewHostNameList"];
            Object hasNewInternetConnectionProfile = localSettings.Values["HasNewInternetConnectionProfile"];
            Object hasNewNetworkConnectivityLevel = localSettings.Values["HasNewNetworkConnectivityLevel"];

            await NetworkStatusWithInternetPresentDispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                string outputText = string.Empty;

                if ((profile != null) && (adapter != null))
                {
                    //If internet profile has changed, display the new internet profile
                    if ((string.Equals(profile.ToString(), internetProfile, StringComparison.Ordinal) == false) ||
                            (string.Equals(adapter.ToString(), networkAdapter, StringComparison.Ordinal) == false))
                    {
                        internetProfile = profile.ToString();
                        networkAdapter = adapter.ToString();
                        outputText += "Internet Profile changed\n" + "=================\n" + "Current Internet Profile : " + internetProfile + "\n\n";

                        if (hasNewConnectionCost != null)
                        {
                            outputText += hasNewConnectionCost.ToString() + "\n";
                        }
                        if (hasNewDomainConnectivityLevel != null)
                        {
                            outputText += hasNewDomainConnectivityLevel.ToString() + "\n";
                        }
                        if (hasNewHostNameList != null)
                        {
                            outputText += hasNewHostNameList.ToString() + "\n";
                        }
                        if (hasNewInternetConnectionProfile != null)
                        {
                            outputText += hasNewInternetConnectionProfile.ToString() + "\n";
                        }
                        if (hasNewNetworkConnectivityLevel != null)
                        {
                            outputText += hasNewNetworkConnectivityLevel.ToString() + "\n";
                        }

                        rootPage.NotifyUser(outputText, NotifyType.StatusMessage);
                    }
                }
            });
        }
开发者ID:badreddine-dlaila,项目名称:Windows-8.1-Universal-App,代码行数:58,代码来源:Scenario1_NetworkStatusWithInternetPresent.xaml.cs


示例8: 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 progress = "Progress: " + args.Progress + "%";
     BackgroundTaskSample.ServicingCompleteTaskProgress = progress;
     UpdateUI();
 }
开发者ID:hirokuma3,项目名称:Windows-universal-samples,代码行数:11,代码来源:Scenario3_ServicingCompleteTask.xaml.cs


示例9: OnCortanaMakeTaskCompleted

 /// <summary>
 /// Event fires after background task completes.
 /// </summary>
 /// <param name="task"></param>
 /// <param name="args"></param>
 private void OnCortanaMakeTaskCompleted(IBackgroundTaskRegistration task, BackgroundTaskCompletedEventArgs args)
 {
    Windows.Storage.ApplicationDataContainer settings = Windows.Storage.ApplicationData.Current.LocalSettings;
    string key = task.TaskId.ToString();
    string message = settings.Values[key].ToString();
 }
开发者ID:sparker2000,项目名称:Make,代码行数:11,代码来源:MainPage.xaml.cs


示例10: RegisterCompletedHandlerforBackgroundTask

 /// <summary>
 /// Register completion handler for registered background task on application startup.
 /// </summary>
 /// <param name="task">The task to attach progress and completed handlers to.</param>
 private bool RegisterCompletedHandlerforBackgroundTask(IBackgroundTaskRegistration task)
 {
     bool taskRegistered = false;
     try
     {
         //Associate background task completed event handler with background task.
         task.Completed += new BackgroundTaskCompletedEventHandler(OnCompleted);
         taskRegistered = true;
     }
     catch (Exception ex)
     {
         rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage);
     }
     return taskRegistered;
 }
开发者ID:badreddine-dlaila,项目名称:Windows-8.1-Universal-App,代码行数:19,代码来源:Scenario1_NetworkStatusWithInternetPresent.xaml.cs


示例11: 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


示例12: 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


示例13: 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


示例14: StopLocationTracker

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


示例15: 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


示例16: 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


示例17: 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


示例18: 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


示例19: 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


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IBanco类代码示例发布时间:2022-05-24
下一篇:
C# IAdapterTransaction类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap