exam questions

Exam 70-483 All Questions

View all questions & answers for the 70-483 exam

Exam 70-483 topic 2 question 7 discussion

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

You are implementing a method named ProcessReports that performs a long-running task. The ProcessReports() method has the following method signature: public void ProcessReports(List<decimal> values,CancellationTokenSource cts, CancellationToken ct)
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 ProcessReports() method performs the required actions.
Which code segment should you use in the method body?

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

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
BurgSharp
Highly Voted 5 years ago
B it is: "By throwing a OperationCanceledException and passing it the token on which cancellation was requested. The preferred way to do this is to use the ThrowIfCancellationRequested method. A task that is canceled in this way transitions to the Canceled state, " link: https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/task-cancellation
upvoted 6 times
...
mohmou
Highly Voted 4 years, 11 months ago
B https://www.briefmenow.org/microsoft/which-code-segment-should-you-use-in-the-method-body-5/
upvoted 5 times
...
DaGrooveNL
Most Recent 4 years, 5 months ago
FINAL ANSWER: B.
upvoted 1 times
...
Jannie
5 years ago
I'dd say A based on this : https://www.c-sharpcorner.com/UploadFile/80ae1e/canceling-a-running-task/
upvoted 2 times
...
nelaed
5 years ago
C is the right answer. https://docs.microsoft.com/pl-pl/dotnet/api/system.threading.cancellationtoken.throwifcancellationrequested?view=netcore-3.1 Body of ThrowIfCancellationRequested(): if (token.IsCancellationRequested) throw new OperationCanceledException(token); Method Cancel from CancellationTokenSource sets flag for canceling work.
upvoted 2 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 ...