An application contains code that measures reaction times. The code runs the timer on a thread
separate from the user interface. The application includes the following code. (Line numbers are
included for reference only.)
You need to ensure that the application cancels the timer when the user presses the Enter key.
Which code segment should you insert at line 14?
A.
tokenSource.Token.Register( () => tokenSource.Cancel() );
B.
tokenSource.Cancel();
C.
tokenSource.IsCancellationRequested = true;
D.
tokenSource.Dispose();
B
B jak baranina w ciescie
B
quite easy actually
if a thread wants to cancel an operation it creates a cancellationTokensource obj.
a cancellable asynchronous operation starts by passing a cancellation token via the token prop of hte cancellationtokensource obj.
by sending a cancellation token the current operation cant initiate the cancellation. if parent thread wants to initiate the cancellation . it calls cancel on teh cancellationtokensource object.
ongoing ops might use the cancellation token to check if a cancellation is pending and respond but ignoring the cancel request is valid.
B