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?

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



Leave a Reply 0

Your email address will not be published. Required fields are marked *