exam questions

Exam 70-483 All Questions

View all questions & answers for the 70-483 exam

Exam 70-483 topic 2 question 51 discussion

Actual exam question from Microsoft's 70-483
Question #: 51
Topic #: 2
[All 70-483 Questions]

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();
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
supersunny
Highly Voted 5 years, 11 months ago
B. tokenSource.Cancel
upvoted 12 times
...
noussa
Most Recent 4 years, 5 months ago
This is why it's B and not C as I thought in the beginning: This property indicates whether cancellation has been requested for this token, either through the token initially being constructed in a canceled state, or through calling Cancel on the token's associated CancellationTokenSource. If this property is true, it only guarantees that cancellation has been requested. It does not guarantee that every registered handler has finished executing, nor that cancellation requests have finished propagating to all registered handlers. Additional synchronization may be required, particularly in situations where related objects are being canceled concurrently.
upvoted 1 times
...
Epit2021
4 years, 6 months ago
N.B. The code doesn't actually check what key was pressed, so it'll always stop the timer.
upvoted 1 times
dutohlav
4 years, 5 months ago
There is Readline() - it can only be sent using Enter. It just ignores what the user wrote into the console before hitting Enter (unlike ReadKey())
upvoted 2 times
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...