Background task example this example shows how to create and register background tasks using Windows to run background task APIs. A background task is a system or time event that can be restricted by one or more conditions. When a background task is triggered, it is associated Program Background of running and executing tasks. A background task can run an application even if the registered background task is paused. This example demonstrates the following: • Create and register background tasks using C # or JavaScript. • Create a background task that is triggered by a system event. • Add a condition to restrict the running of background tasks only when the condition is actually. • Report the background task progress and complete it to the foreground application. • Process and cancel background tasks. • Initialize the task process and background completion handler when starting the application. Private Void Onprogress (ibackgroundtaskregistration sender, backgroundtaskprogresseventargs E)
{
//
// Update the UI with progress reported by the background task.
//
Sampledispatcher. invokeasync (coredispatcherpriority. Normal,
(Task, argS) =>
{
VaR Taskregistration = task As Ibackgroundtaskregistration;
VaR Progressargs = args. Context As Backgroundtaskprogresseventargs;
If (Task! = Null ) & (ARGs! = Null ))
{
Switch (Taskregistration. Name)
{
Case Samplebackgroundtaskname:
Samplebackgroundtaskprogress. Text = " Progress: " + Progressargs. Progress + " % " ;
Break ;
Case Samplebackgroundtaskwithconditionname:
Samplebackgroundtaskwithconditionprogress. Text = " Progress: " + Progressargs. Progress + " % " ;
Break ;
Case Servicingcompletetaskname:
Servicingcompleteprogress. Text = " Progress: " + Progressargs. Progress + " % " ;
Break ;
Case Timetriggeredtaskname:
Timetriggeredbackgroundtaskprogress. Text = " Progress: " + Progressargs. Progress + " % " ;
Break ;
}
}
},
Sender,
E );
}
Complete example/files/risk/windows8/background task sample.rar