PrepAway - Latest Free Exam Questions & Answers

You need to update the DoWork() method of the background task to meet the requirements

You need to update the DoWork() method of the background task to meet the requirements.
What should you do? (Each correct answer presents part of the solution. Choose all that apply.)

PrepAway - Latest Free Exam Questions & Answers

A.
Get the IsCancellationRequested property from the CancellationToken object and return a
TaskCompletionSource object.

B.
Access the Progress object and report the task’s progress to the caller.

C.
Update the DoWork() method to receive a Progress object.

D.
Add the CancellationToken object to the client.GetAsync() method.

E.
Confirm that the IsCancellationRequested property of the CancellationToken object is true and
exit the task.

F.
Update the DoWork() method to receive a CancellationToken object in the arguments of the
method.

Explanation:

Cancellation is controlled by the CancellationToken structure. You expose cancellation tokens in the
signature of cancelable async methods, enabling them to be shared between the task and caller. In
the most common case, cancellation follows this flow:
1. (D) The caller creates a CancellationTokenSource object.
2. (F) The caller calls a cancelable async API, and passes the CancellationToken from the
CancellationTokenSource (CancellationTokenSource.Token).
3. The caller requests cancellation using the CancellationTokenSource object
(CancellationTokenSource.Cancel()).
4. (E)The task acknowledges the cancellation and cancels itself, typically using the
CancellationToken.ThrowIfCancellationRequested method.
* From scenario:
/ The SocialPoller background task must run the code in the DoWork() method to collect content
from the Contoso feed.
/ The UI must always remain responsive to user actions.
Note:
* Task-based Asynchronous Pattern
* CancellationToken Structure
/ Propagates notification that operations should be canceled.
/ CancellationToken. IsCancellationRequested
Gets whether cancellation has been requested for this token.


Leave a Reply