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();

One Comment on “Which code segment should you use in the method body?


Leave a Reply