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

C# Background.BackgroundTaskBuilder类代码示例

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

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



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

示例1: RegisterTasks

        private async Task RegisterTasks()
        {
            // Applications must have lock screen privileges in order to receive raw notifications
            var backgroundStatus = await BackgroundExecutionManager.RequestAccessAsync();

            // Make sure the user allowed privileges
            if (backgroundStatus != BackgroundAccessStatus.Denied && backgroundStatus != BackgroundAccessStatus.Unspecified)
            {
                var systemEventTaskBuilder = new BackgroundTaskBuilder();
                var systemEventTrigger = new SystemTrigger(SystemTriggerType.InternetAvailable, false);
                systemEventTaskBuilder.AddCondition(new SystemCondition(SystemConditionType.InternetAvailable));
                systemEventTaskBuilder.SetTrigger(systemEventTrigger);

                // Background tasks must live in separate DLL, and be included in the package manifest
                // Also, make sure that your main application project includes a reference to this DLL
                systemEventTaskBuilder.TaskEntryPoint = SystemEventTaskEntryPoint;
                systemEventTaskBuilder.Name = SystemEventTaskName;

                try
                {
                    var task = systemEventTaskBuilder.Register();
                    task.Completed += this.SystemEventBackgroundTaskCompleted;
                }
                catch (Exception ex)
                {
                    // Should probably log this somewhere...
                }
            }
            else
            {
                // Should probably log this somewhere...
            }
        }
开发者ID:gep13,项目名称:WindowsPhoneSample,代码行数:33,代码来源:BackgroundTaskService.cs


示例2: RegisterBackgroundTask

        /// <summary>
        /// Register a background task with the specified taskEntryPoint, name, trigger,
        /// and condition (optional).
        /// </summary>
        /// <param name="taskEntryPoint">Task entry point for the background task.</param>
        /// <param name="name">A name for the background task.</param>
        /// <param name="trigger">The trigger for the background task.</param>
        /// <param name="condition">An optional conditional event that must be true for the task to fire.</param>
        public static BackgroundTaskRegistration RegisterBackgroundTask(String taskEntryPoint, String name)
        {
            BackgroundTaskRegistration task = null;
            try
            {
                var builder = new BackgroundTaskBuilder();

                builder.Name = name;
                builder.TaskEntryPoint = taskEntryPoint;
                DeviceUseTrigger de = new DeviceUseTrigger();
               // de.RequestAsync();
            //    builder.SetTrigger(new TimeTrigger(15, true));
                task = builder.Register();
            }
            catch(Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception while registering background task: " + e.Message);
            }
            UpdateBackgroundTaskStatus(name, true);

            //
            // Remove previous completion status from local settings.
            //
            var settings = ApplicationData.Current.LocalSettings;
            settings.Values.Remove(name);

            return task;
        }
开发者ID:flecoqui,项目名称:Windows10,代码行数:36,代码来源:AudioDiscoveryTaskManager.cs


示例3: RegisterCortanaIntegrationTask

      /// <summary>
      /// Registers the background task that makes cortana listen to defined keywords
      /// </summary>
      private void RegisterCortanaIntegrationTask()
      {
         // Tracks whether the background task has been registerd or not.
         bool taskRegistered = false;
         string taskName = "CortanaMake";

         // Search background tasks registrations for the task name
         foreach (KeyValuePair<Guid, IBackgroundTaskRegistration> task in BackgroundTaskRegistration.AllTasks)
         {
            if (task.Value.Name == taskName)
            {
               taskRegistered = true;
               break;
            }
         }

         // Register the task if it hasn't already been registered
         if(!taskRegistered)
         {
            BackgroundTaskBuilder builder = new BackgroundTaskBuilder();
            builder.Name = taskName;
            builder.TaskEntryPoint = "BackgroundComponent"; // This is the name of a background task that needs to get created.  When the task is run, 
                                                            // the public void Run(IBackgroundTaskInstance taskInstance) will be called in this library.  
                                                            // We also have to register this in our app manifest.
            builder.SetTrigger(new SystemTrigger(SystemTriggerType.TimeZoneChange, false));
            BackgroundTaskRegistration task = builder.Register();
            task.Completed += new BackgroundTaskCompletedEventHandler(OnCortanaMakeTaskCompleted);
         }
      }
开发者ID:sparker2000,项目名称:Make,代码行数:32,代码来源:MainPage.xaml.cs


示例4: PushNotifications

        /// <summary>
        /// The register task.
        /// </summary>
        private static async void PushNotifications()
        {
            const string PushNotificationTaskName = "ToastNotifications";

            if (GetRegisteredTask(PushNotificationTaskName) != null)
            {
                return;
            }

            var ns = new NotificationStore();
            ns.Register();

            await BackgroundExecutionManager.RequestAccessAsync();

            await ObtainLockScreenAccess();
            var taskBuilder = new BackgroundTaskBuilder
                                  {
                                      Name = PushNotificationTaskName,
                                      TaskEntryPoint = typeof(PushNotificationTask).FullName
                                  };

            var trigger = new PushNotificationTrigger();
            taskBuilder.SetTrigger(trigger);

            var internetCondition = new SystemCondition(SystemConditionType.InternetAvailable);
            taskBuilder.AddCondition(internetCondition);

            try
            {
                taskBuilder.Register();
            }
            catch (Exception exception)
            {
            }
        }
开发者ID:jlkalberer,项目名称:Linkslap.WP,代码行数:38,代码来源:RegisterTasks.cs


示例5: StartInBackground_Click

        private async void StartInBackground_Click(object s, RoutedEventArgs e)
        {
            var backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync();
            var geofenceTaskBuilder = new BackgroundTaskBuilder
            {
                Name = "GeofenceBackgroundTask",
                TaskEntryPoint = "BackgroundTask.GeofenceBackgroundTask"
            };

            var trigger = new LocationTrigger(LocationTriggerType.Geofence);
            geofenceTaskBuilder.SetTrigger(trigger);
            var geofenceTask = geofenceTaskBuilder.Register();
            geofenceTask.Completed += (sender, args) =>
            {
                var geoReports = GeofenceMonitor.Current.ReadReports();
                foreach (var geofenceStateChangeReport in geoReports)
                {
                    var id = geofenceStateChangeReport.Geofence.Id;
                    var newState = geofenceStateChangeReport.NewState.ToString();
                    Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        new MessageDialog(newState + " : " + id)
                        .ShowAsync());
                }
            };
        }
开发者ID:nagendraksrivastava,项目名称:GeofencingWP81,代码行数:25,代码来源:MainPage.xaml.cs


示例6: OnNavigatedTo

        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.Parameter is int)
            {
                Pivot.SelectedIndex = (int) e.Parameter;
            }
            LiveTileToggle.IsEnabled = App.MainViewModel.SignOnSaved;
            NotificationsToggle.IsEnabled = App.MainViewModel.SignOnSaved;
            VerifyIdToggle.IsEnabled = App.MainViewModel.SignOnSaved;

            LiveTileToggle.IsOn = (bool) (localSettings[App.RL.GetString("TileSettingString")] ?? false);
            NotificationsToggle.IsOn = (bool) (localSettings[App.RL.GetString("NotificationSettingString")] ?? false);
            VerifyIdToggle.IsOn = (bool)(localSettings[App.RL.GetString("VerifyIdSettingString")] ?? false);

            if (App.MainViewModel.SignOnSaved)
            {
                string taskName = App.RL.GetString("BackgroundTaskName");
                if (!IsTaskRegistered(taskName))
                {
                    var builder = new BackgroundTaskBuilder();
                    builder.Name = taskName;
                    builder.TaskEntryPoint = "BackgroundUpdater.BalanceCheck";
                    builder.SetTrigger(new TimeTrigger(15, false));
                    //builder.AddCondition(new SystemCondition(SystemConditionType.InternetAvailable)); //this doesn't work...

                    await BackgroundExecutionManager.RequestAccessAsync();

                    BackgroundTaskRegistration task = builder.Register();

                }
            }

            base.OnNavigatedTo(e);
        }
开发者ID:parkerreno,项目名称:FoodTile,代码行数:34,代码来源:Settings.xaml.cs


示例7: registerBackgroundTask

        public async void registerBackgroundTask()
        {
            try
            {
                var result = await BackgroundExecutionManager.RequestAccessAsync();
                if (result == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity ||
                    result == BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity)
                {
                    foreach (var task in BackgroundTaskRegistration.AllTasks)
                    {
                        if (task.Value.Name == TASK_NAME)
                            task.Value.Unregister(true);
                    }

                    BackgroundTaskBuilder builder = new BackgroundTaskBuilder();
                    builder.Name = TASK_NAME;
                    builder.TaskEntryPoint = TASK_ENTRY;
                    builder.SetTrigger(new TimeTrigger(15, false));
                    var registration = builder.Register();
                }
                for (int i = 0; i < 5; i++)
                {
                    Uri u = new Uri("ms-appx:///tile/TileTemplate" + new Random().Next(1, 3).ToString() + ".xml");
                    StorageFile xmlFile = await StorageFile.GetFileFromApplicationUriAsync(u);
                    XmlDocument doc = await XmlDocument.LoadFromFileAsync(xmlFile);
                    TileNotification notifi = new TileNotification(doc);
                    TileUpdater udt = TileUpdateManager.CreateTileUpdaterForApplication();
                    udt.Update(notifi);
                }
            }
            catch(Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
            }
        }
开发者ID:DXChinaTE,项目名称:BankApp,代码行数:35,代码来源:Register.cs


示例8: RegisterBackgroundTasks

        private async void RegisterBackgroundTasks()
        {
            var builder = new BackgroundTaskBuilder
            {
                Name = "BackgroundUpdateReadingList",
                TaskEntryPoint = "EasyReader.BackgroundTasks.UpdateReadingList"
            };

            try
            {
                await BackgroundExecutionManager.RequestAccessAsync();
            }
            catch (Exception)
            {
                
            }

            IBackgroundTrigger trigger = new TimeTrigger(15, true);
            builder.SetTrigger(trigger);

            IBackgroundCondition condition = new SystemCondition(SystemConditionType.InternetAvailable);
            builder.AddCondition(condition);

            IBackgroundTaskRegistration task = builder.Register();

            task.Progress += task_Progress;
            task.Completed += task_Completed;
        }
开发者ID:beaugunderson,项目名称:EasyReader,代码行数:28,代码来源:App.xaml.cs


示例9: RegisterTask

        private async void RegisterTask()
        {
            var access = await BackgroundExecutionManager.RequestAccessAsync();
            if (access == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity)
            {
                // Create a new background task builder.
                BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();

                // Create a new Phone Trigger.
                PhoneTrigger trigger = new PhoneTrigger(PhoneTriggerType.CallOriginDataRequest, false);

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

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

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

                // Register the background task.
                BackgroundTaskRegistration taskRegistration = taskBuilder.Register();

                UpdateBackgroundTaskUIState(true);
                rootPage.NotifyUser("Registered Caller ID background task", NotifyType.StatusMessage);
            }
            else
            {
                rootPage.NotifyUser("Background agent access denied", NotifyType.ErrorMessage);
            }
        }
开发者ID:RasmusTG,项目名称:Windows-universal-samples,代码行数:31,代码来源:Scenario1_Register.xaml.cs


示例10: UpdateTile

        private async Task UpdateTile()
        {
            var result = await BackgroundExecutionManager.RequestAccessAsync();
            if (result == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity ||
                result == BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity)
            {
                foreach (var task in BackgroundTaskRegistration.AllTasks)
                {
                    if (task.Value.Name == TASK_NAME)
                        task.Value.Unregister(true);

                    //task.Value.Progress += new BackgroundTaskProgressEventHandler(OnProgress);
                    //task.Value.Completed += new BackgroundTaskCompletedEventHandler(OnCompleted);
                }

                BackgroundTaskBuilder builder = new BackgroundTaskBuilder();
                var condition = new SystemCondition(SystemConditionType.InternetAvailable);

                builder.Name = TASK_NAME;
                builder.AddCondition(condition);
                builder.TaskEntryPoint = TASK_ENTRY;
                builder.SetTrigger(new TimeTrigger(15, false));
                var registration = builder.Register();

                registration.Progress += new BackgroundTaskProgressEventHandler(task_Progress);
                registration.Completed += new BackgroundTaskCompletedEventHandler(task_Completed);

            }
        }
开发者ID:stavrianosy,项目名称:BudgetManagementAssistant,代码行数:29,代码来源:MainPage.xaml.cs


示例11: Register

        /// <summary>
        /// 屏幕点亮时执行该任务:UserPresent
        /// http://msdn.microsoft.com/library/windows/apps/windows.applicationmodel.background.systemtriggertype.aspx
        /// </summary>
        /// <param name="taskEntryPoint">后台任务名</param>
        public static async void Register(string taskEntryPoint)
        {
            BackgroundExecutionManager.RemoveAccess();
            var status = await BackgroundExecutionManager.RequestAccessAsync();
            if (status == BackgroundAccessStatus.Unspecified || status == BackgroundAccessStatus.Denied)
            {
                await new MessageDialog("系统关闭了后台运行,请前往‘系统设置’进行设置").ShowAsync();
                return;
            }
            else
            {
                var taskReg = BackgroundTaskRegistration.AllTasks.Values.FirstOrDefault(t => t.Name.Equals(LIVETILETASK)) as BackgroundTaskRegistration;

                if (taskReg == null)
                {
                    //注册任务
                    var taskBuilder = new BackgroundTaskBuilder
                    {
                        Name = LIVETILETASK,
                        TaskEntryPoint = taskEntryPoint
                    };

                    var trigger = new SystemTrigger(SystemTriggerType.UserPresent, false);
                    taskBuilder.SetTrigger(trigger);
                    taskBuilder.Register();
                }
                else
                {
                    return;
                }
            }
        }
开发者ID:hippieZhou,项目名称:OneUWP,代码行数:37,代码来源:BackgroundTaskManager.cs


示例12: RegisterBackGroundTask

        public static BackgroundTaskRegistration RegisterBackGroundTask(string taskEntryPoint,
                                                                        string taskName,
                                                                        IBackgroundTrigger trigger,
                                                                        IBackgroundCondition condition)
        {
            //Check if its alterady Registrated
            foreach (var cur in BackgroundTaskRegistration.AllTasks)
            {
                if (cur.Value.Name == taskName)
                {
                    return (BackgroundTaskRegistration)(cur.Value);
                }
            }

            //Register the Task
            var builder = new BackgroundTaskBuilder();
            builder.Name = taskName;
            builder.TaskEntryPoint = taskEntryPoint;

            if (trigger != null)
            {
                builder.SetTrigger(trigger);
            }

            if (condition != null)
            {
                builder.AddCondition(condition);
            }

            BackgroundTaskRegistration task = builder.Register();

            return task;
        }
开发者ID:ernestoguimaraes,项目名称:cortana,代码行数:33,代码来源:Util.cs


示例13: RegisterTask

        /// <summary>
        /// Method reponsible for registering the background task
        /// </summary>
        private async void RegisterTask()
        {
            var taskRegistered = Windows.ApplicationModel.Background.BackgroundTaskRegistration.AllTasks.Select(task => task.Value.Name == nameof(TileUpdaterTask)).Count() > 0;
            if (taskRegistered)
            {
                this.StatusLabel.Text = "Task already registered!";
            }
            else
            {
                // Check if task is registred
                BackgroundAccessStatus allowed = await BackgroundExecutionManager.RequestAccessAsync();

                if (allowed == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity || allowed == BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity)
                {
                    var task = new BackgroundTaskBuilder
                    {
                        Name = nameof(TileUpdaterTask),
                        CancelOnConditionLoss = false,
                        TaskEntryPoint = typeof(TileUpdaterTask).ToString(),
                    };

                    task.SetTrigger(new TimeTrigger(15, false));
                    task.AddCondition(new SystemCondition(SystemConditionType.UserPresent));
                    task.Register();                    

                    this.StatusLabel.Text = "Task has been registered!";
                }
                else
                {
                    this.StatusLabel.Text = "Not allowd to register task!";
                }                
            }
        }
开发者ID:talkitbr,项目名称:TDC2015,代码行数:36,代码来源:MainPage.xaml.cs


示例14: RegisterBackgroundTask

        /// <summary>
        /// We proceed to register the task if it hasn't been registered yet. Otherwise, we fetch the registration
        /// and retrieve the ApplicationTrigger from there.
        /// </summary>
        private async void RegisterBackgroundTask()
        {
            try
            {
                if (!BackgroundTaskRegistration.AllTasks.Any(reg => reg.Value.Name == TileRegistrationName))
                {
                    // Configure task parameters
                    BackgroundTaskBuilder builder = new BackgroundTaskBuilder();
                    builder.TaskEntryPoint = typeof(TileUpdateTask).FullName;
                    builder.Name = TileRegistrationName;

                    // Remember to set an ApplicationTrigger so we can run it on demand later
                    this.backgroundTrigger = new ApplicationTrigger();
                    builder.SetTrigger(backgroundTrigger);
                    builder.Register();

                    MessageDialog infoDialog = new MessageDialog("Background task successfully registered.", "Info");
                    await infoDialog.ShowAsync();
                }
                else
                {
                    // Fetch registration details and trigger if already existing
                    var registration = BackgroundTaskRegistration.AllTasks.FirstOrDefault(reg => reg.Value.Name == TileRegistrationName).Value as BackgroundTaskRegistration;
                    this.backgroundTrigger = registration.Trigger as ApplicationTrigger;

                    MessageDialog infoDialog = new MessageDialog("Background task registration data successfully retrieved.", "Info");
                    await infoDialog.ShowAsync();
                }
            }
            catch (Exception ex)
            {
                MessageDialog errorDialog = new MessageDialog("There was an error while trying to register the background task.", "Error");
                errorDialog.ShowAsync();
            }
        }
开发者ID:r2d2rigo,项目名称:UWP-Samples,代码行数:39,代码来源:MainPage.xaml.cs


示例15: RegisterApplicationTrigger

        public static async Task RegisterApplicationTrigger(Type backgroundTaskType)
        {
            var backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync();

            if (backgroundAccessStatus == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity ||
                backgroundAccessStatus == BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity)
            {
                var appTrigger = new ApplicationTrigger();
                string taskEntryPoint = backgroundTaskType.ToString();
                var backgroundTaskBuilder = new BackgroundTaskBuilder
                {
                    Name = backgroundTaskType.Name,
                    TaskEntryPoint = taskEntryPoint
                };

                backgroundTaskBuilder.SetTrigger(appTrigger);

                var task = BackgroundTaskRegistration.AllTasks.Values.FirstOrDefault(i => i.Name.Equals(backgroundTaskType.Name));
                task?.Unregister(true);
                backgroundTaskBuilder.Register();

                ValueSet message = new ValueSet { { "Command", "Init" } };

                var result = await appTrigger.RequestAsync(message);

                if (result == ApplicationTriggerResult.Allowed)
                {
                    Debug.WriteLine(string.Format("{0} called!", backgroundTaskType.Name));
                }
            }
        }
开发者ID:sanjayasl,项目名称:Events,代码行数:31,代码来源:BackgroundTaskHelper.cs


示例16: Register

        public static void Register()
        {
             
            foreach (var iter in BackgroundTaskRegistration.AllTasks)
            {
                IBackgroundTaskRegistration mytask = iter.Value;
                if (mytask.Name == "ExampleBackgroundTask")
                {

                    mytask.Unregister(true);
                    break;
                }
            }

           
            var builder = new BackgroundTaskBuilder();
            PushNotificationTrigger trigger = new PushNotificationTrigger();
            builder.SetTrigger(trigger);
            builder.Name = "ExampleBackgroundTask";
            builder.TaskEntryPoint = "Usergrid.Notifications.ExampleBackgroundTask";

            ExampleBackgroundTask.task = builder.Register();
            task.Progress += task_Progress;

            task.Completed += task_Completed;

        }
开发者ID:xiongtec,项目名称:usergrid,代码行数:27,代码来源:BackgroundTask.cs


示例17: RegisterTaskButton_Click

        private void RegisterTaskButton_Click(Object sender, RoutedEventArgs e)
        {
            if (GetRegisteredTask() == null)
            {
                BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();
                MaintenanceTrigger trigger = new MaintenanceTrigger(MAINTENANCE_INTERVAL, false);
                taskBuilder.SetTrigger(trigger);
                taskBuilder.TaskEntryPoint = PUSH_NOTIFICATIONS_TASK_ENTRY_POINT;
                taskBuilder.Name = PUSH_NOTIFICATIONS_TASK_NAME;

                SystemCondition internetCondition = new SystemCondition(SystemConditionType.InternetAvailable);
                taskBuilder.AddCondition(internetCondition);

                try
                {
                    taskBuilder.Register();
                    rootPage.NotifyUser("Task registered", NotifyType.StatusMessage);
                }
                catch (Exception ex)
                {
                    rootPage.NotifyUser("Error registering task: " + ex.Message, NotifyType.ErrorMessage);
                }
            }
            else
            {
                rootPage.NotifyUser("Task already registered", NotifyType.ErrorMessage);
            }
        }
开发者ID:WHISHWORKS,项目名称:MuleSummit2013,代码行数:28,代码来源:ScenarioInput2.xaml.cs


示例18: addBackgroundTask

        /// <summary>
        /// 增加后台任务
        /// </summary>
        private async void addBackgroundTask()
        {
            bool taskRegistered = false;
            //判断是否已经注册过了
            taskRegistered = BackgroundTaskRegistration.AllTasks.Any(x => x.Value.Name == exampleTaskName);

            if (!taskRegistered)
            {
                BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync();
                var builder = new BackgroundTaskBuilder();
                builder.Name = exampleTaskName;
                builder.TaskEntryPoint = "Tasks.LetterBackgroundTask";
                //后台触发器,可多个
                builder.SetTrigger(new SystemTrigger(SystemTriggerType.NetworkStateChange, false));
                builder.SetTrigger(new SystemTrigger(SystemTriggerType.InternetAvailable, false));
                //builder.SetTrigger(new MaintenanceTrigger(15, false)); //定时后台任务
                builder.AddCondition(new SystemCondition(SystemConditionType.InternetAvailable));

                BackgroundTaskRegistration task = builder.Register();
            }
            else
            {
                var cur = BackgroundTaskRegistration.AllTasks.FirstOrDefault(x => x.Value.Name == exampleTaskName);
                BackgroundTaskRegistration task = (BackgroundTaskRegistration)(cur.Value);
            }

        }
开发者ID:cappuccinoqi,项目名称:Date_Windows,代码行数:30,代码来源:App.xaml.cs


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


示例20: RegisterBackgroundTasks

        private async void RegisterBackgroundTasks()
        {
            var access = await BackgroundExecutionManager.RequestAccessAsync();
            if (access == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity || access == BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity)
            {
                TimeTrigger taskTrigger = new TimeTrigger(15, false);
                foreach (var _task in BackgroundTaskRegistration.AllTasks)
                {
                    if (_task.Value.Name == "WPGetListUpdateTimer" || _task.Value.Name=="WPGetListUpdateInternet")
                    {
                        _task.Value.Unregister(true);
                    }
                }
                SystemTrigger striger = new SystemTrigger(SystemTriggerType.InternetAvailable, false);
                var bgTaskBuilder = new BackgroundTaskBuilder();
                bgTaskBuilder.Name = "WPGetListUpdateTimer";
                bgTaskBuilder.TaskEntryPoint = "BackgroundTaskWinMD.WPGetListUpdateBackgroundTask";
                bgTaskBuilder.SetTrigger(taskTrigger);
                // условие, согласно которому триггер будет выполнен только если интернет доступен
                SystemCondition internetCondition = new SystemCondition(SystemConditionType.InternetAvailable);
                bgTaskBuilder.AddCondition(internetCondition);
                BackgroundTaskRegistration task = bgTaskBuilder.Register();

                bgTaskBuilder = new BackgroundTaskBuilder();
                bgTaskBuilder.Name = "WPGetListUpdateInternet";
                bgTaskBuilder.TaskEntryPoint = "BackgroundTaskWinMD.WPGetListUpdateBackgroundTask";
                bgTaskBuilder.SetTrigger(striger);
                
                bgTaskBuilder.AddCondition(internetCondition);
                BackgroundTaskRegistration task2 = bgTaskBuilder.Register();

            }
        }
开发者ID:polushinmk,项目名称:WordPressPluginsUpdate,代码行数:33,代码来源:App.xaml.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Background.BackgroundTaskCompletedEventArgs类代码示例发布时间:2022-05-26
下一篇:
C# Activation.SplashScreen类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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