Exam 70-483 Topic 8 Question 103 Discussion

Actual exam question for Microsoft's 70-483 exam
Question #: 103
Topic #: 8
You are implementing a method named ProcessData that performs a long-running task. The ProcessData() method has the following method signature:
public void ProcessData(List<decimal> values, CancellationTokenSource source, CancellationToken token) If the calling code requests cancellation, the method must perform the following actions:
* Cancel the long-running task.
* Set the task status to TaskStatus.Canceled.
You need to ensure that the ProcessData() method performs the required actions.
Which code segment should you use in the method body?

Suggested Answer: C Vote an answer

Explanation
The CancellationToken.ThrowIfCancellationRequested method throws a OperationCanceledException if this token has had cancellation requested.
This method provides functionality equivalent to:
C#
if (token.IsCancellationRequested)
throw new OperationCanceledException(token);
Reference: CancellationToken.ThrowIfCancellationRequested Method ()
https://msdn.microsoft.com/en-us/library/system.threading.cancellationtoken.throwifcancellationrequested(v=vs.

by Drew at Feb 04, 2024, 04:28 AM

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
Nick name: Submit Cancel
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

0
0
0
10