Which code segment should you use in the method body?

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?

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



Leave a Reply 6

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


Twórca C#

Twórca C#

B jak Baran

Najlepszy Programista Swiata

Najlepszy Programista Swiata

B jak kurwa

Najlepszy Programista Swiata

Najlepszy Programista Swiata

B jak Biele Rozy

Lord Vader

Lord Vader

public bool IsCancellationRequested { get; }

Type: System.Boolean
true if cancellation has been requested for this CancellationTokenSource; otherwise, false.//checks if cancellation has been called

Throws a OperationCanceledException if this token has had cancellation requested. // cancels the long running task

B.