PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use in the method body?

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?

PrepAway - Latest Free Exam Questions & Answers

A.
if (token.IsCancellationRequested)
return;

B.
throw new AggregateException();

C.
token.ThrowIfCancellationRequested();

D.
source.Cancel();

4 Comments on “Which code segment should you use in the method body?

  1. Dai Nguyen says:

    “If the calling code requests cancellation”
    It means source.Cancel() was called in main thread, after that TaskStatus was set to Cancelled.
    We will “return” inside each Task to Cancel the long-running task.
    So A is correct answer.




    1



    0

Leave a Reply