PrepAway - Latest Free Exam Questions & Answers

Which three actions should you perform in sequence?

DRAG DROP
You are developing a Windows Store app that uploads large files to the Internet by using background tasks.
uploadTask is an instance of the IBackgroundTask interface that provides access to a background
task instance. UploadFilesAsync() is the asynchronous method that performs the upload.
You need to ensure that the app performs the upload operation asynchronously in a background task.
Which three actions should you perform in sequence? (To answer, move the appropriate actions
from the list of actions to the answer area and arrange them in the correct o^de-“.)

PrepAway - Latest Free Exam Questions & Answers

Answer: See the explanation.

Explanation:

Box 1:

Box 2:

Box 3:

Note:
* If you run any asynchronous code in your background task, then your background task needs to
use a deferral. If you don’t use a deferral, then the background task process can terminate
unexpectedly if the Run method completes before your asynchronous method call has completed.
Request the deferral in the Run method before calling the asynchronous method. Save the deferral
to a global variable so it can be accessed from the asynchronous method. Declare the deferral
complete after the asynchronous code completes.
* Example:

The following sample code gets the deferral, saves it, and releases it when the asynchronous code is
complete:
C#C++
public async void Run(IBackgroundTaskInstance taskInstance)
{
BackgroundTaskDeferral _deferral = taskInstance.GetDeferral(); // Box 1
//
// TODO: Insert code to start one or more asynchronous methods using the
// await keyword, for example:
// Box 2:
// await ExampleMethodAsync();
//
_deferral.Complete(); // Box 3
}
Reference:
Quickstart: Create and register a background task (Windows Runtime apps using C#/VB/C++ and
XAML)


Leave a Reply