Windows 8.1 application development background task Overview (Windows XAML)

Source: Internet
Author: User

Speaking of background tasks, this is one of the frequently mentioned topics when chatting with many Android Developers. The background tasks of Windows Mobile Platforms are different from those of Android background services, simply put, on the Windows RT mobile platform, only when certain conditions are met can some pre-configured code be run. Windows 8.1 and Windows Phone 8.0 have some differences in background tasks. Today I will introduce background tasks on the Windows 8.1 mobile platform and their operating conditions.

First, we will introduce the background scenarios of Windows Mobile platform applications.

Today, I will only introduce the following basic tasks: background tasks respond to system events (background task running conditions, ServicingComplete-application update triggers), maintenance triggers, and timer background tasks, I will introduce these content one by one.

Before that, I will introduce the background application configuration.

Manually declare the supported background task types in the Package. appxmanifest File

Declaration in the <Extensions> node

                                                                 

For example:

                                          

You can also select the option directly on the graphic interface. Note: it is very important to manually enter the Entry Point field. This field must be followed by BackgroundTaskBuilder. taskEntryPoint registers the task with the same parameters (to declare the permissions of the background proxy and the namespace for running the proxy logic)

:

You need to create a background task class for the running logic itself (business logic) (the specific steps are based on the original MSDN Statement)

You can write the code for implementationIBackgroundTaskInterface Class to run code in the background. When usingSystemTriggerOrMaintenanceTriggerWhen a trigger triggers a specific event, the code is run.

The following steps describe how to write and implementIBackgroundTaskA new class of the interface. Before you start, create a new project for the background task in the solution. Add a new empty class for Background tasks and import the Windows. ApplicationModel. Background namespace.

  • Create a new project for the background task and add it to your solution. To do this, right-click your solution and choose "add"> "new project ". Select the component project type when running Windows, name the project, and click OK ".
  • Reference the background task project from the Windows App Store app. First, right-click your Windows application store application project and select "properties". Then, go to "common properties" and click "Add new reference" to select the check box next to the background task project, click "OK" in the two dialog boxes ".
  • Create an implementationIBackgroundTaskInterface.RunThe method is the input point that must be called when a specified event is triggered. This method is required for each background task.

    Note:The background task class (and all other classes in the background task project) must belongSealedOfPublicClass.

   =                                

Register the background proxy in the application (you can select the background proxy when registering the background proxy)

Step 1: Define the method signature and return the type

This method includes the task entry point, Task Name, pre-built background task trigger, and background taskSystemCondition(Optional ). This method returnsBackgroundTaskRegistrationObject.

The following is a background task triggered when system events are captured. It is called SystemTrigger.

BackgroundTaskRegistration RegisterBackgroundTask (cur. Value. Name = builder = (condition! =

The methods used to write the ServicingComplete trigger are the same in the event trigger format. The trigger is triggered after the application is updated.

Maintenance trigger

Use the maintenance trigger to run the task every 15 minutes. Maintenance tasks only run when the device is plugged into the AC power, instead of on the screen lock. Here I will reference MSDN

Create a newMaintenanceTriggerObject. Second ParameterOneShotSpecifies whether the maintenance task runs once or continues to run periodically. IfOneShotIf it is set to true, the first parameter (FreshnessTimeSpecifies the number of minutes to wait before the background task is scheduled. IfOneShotIf it is set to falseFreshnessTimeSpecifies the Running frequency of background tasks.

Note:IfFreshnessTimeIf it is set to less than 15 minutes, an exception is thrown when you try to register a background task.

 waitIntervalMinutes = =  MaintenanceTrigger(waitIntervalMinutes, =  entryPoint =  taskName   = = RegisterBackgroundTask(entryPoint, taskName, taskTrigger, exampleCondition);

The creation method is still very similar to SystemTrigger.

Create time trigger

  • Create a newTimeTrigger. Second ParameterOneShotSpecifies whether the background task runs once or periodically. IfOneShotIf it is set to true, the first parameter (FreshnessTimeSpecifies the number of minutes to wait before the background task is scheduled. IfOneShotIf it is set to falseFreshnessTimeSpecifies the Running frequency of background tasks.

    Windows 8 has a built-in timer for running background tasks at 15 minutes.

  • IfFreshnessTimeSet to 15 minutes andOneShotIf this parameter is set to true, the task starts from its registration and runs once.

  • IfFreshnessTimeSet to 15 minutes andOneShotIf this parameter is set to false, the task starts from its registration and runs once.

  • Note:IfFreshnessTimeIf it is set to less than 15 minutes, an exception is thrown when you try to register a background task.

TimeTrigger hourlyTrigger =  TimeTrigger(, =  entryPoint = taskName   == RegisterBackgroundTask(entryPoint, taskName, hourlyTrigger, userCondition);

 

For details about other triggers, see ):

 

 

Or your application has very high requirements on real-time backend performance. Consider the following:

MSDN is very talkative. I have translated it into an adult saying,

PushNotificationTrigger is actually the background proxy that is executed only when the application is pushed. It is used to extend the functions of push to the application.

ControlChannelTrigger is a solution for applications that cannot use the wns push Service, or for privacy or message service level agreement (SLA) issues.

Http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj662741.aspx for details

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.