exam questions

Exam 70-483 All Questions

View all questions & answers for the 70-483 exam

Exam 70-483 topic 2 question 80 discussion

Actual exam question from Microsoft's 70-483
Question #: 80
Topic #: 2
[All 70-483 Questions]

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?

  • A. if (token.IsCancellationRequested)return;
  • B. throw new AggregateException();
  • C. token.ThrowIfCancellationRequested();
  • D. source.Cancel();
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
supersunny
Highly Voted 5 years, 10 months ago
C is correct
upvoted 12 times
...
nelaed
Most Recent 5 years, 1 month ago
Why not D? If we use ThrowIfCancellationRequestes then IsCancellationRequested is still set to false.
upvoted 2 times
BurgSharp
4 years, 11 months ago
That is actually what the calling code will do to request cancellation. The Answer is C.
upvoted 4 times
...
Kilsimon
4 years, 8 months ago
It is kinda awkward, but "ThrowIfCancellationRequested()" sets the TaskStatus.Cancel while "Cancel()" does not, which is the reason that D is not the answer.
upvoted 3 times
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
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.

SaveCancel
Loading ...