exam questions

Exam 70-480 All Questions

View all questions & answers for the 70-480 exam

Exam 70-480 topic 1 question 20 discussion

Actual exam question from Microsoft's 70-480
Question #: 20
Topic #: 1
[All 70-480 Questions]

HOTSPOT -
You are creating a web worker for an HTML5 application.
The following tasks must be performed from within the web worker:
✑ Register an event listener for the web worker
✑ Start and stop the web worker
You need to define a function that performs the required tasks.
Which code segment should you use? (To answer, select the appropriate option from the drop-down list in the answer area.)
Hot Area:

Show Suggested Answer Hide Answer
Suggested Answer:
* addEventListener
The addEventListener() method attaches an event handler to the specified element.
In context of a worker, both self and this refer to the global scope. The worker can either add an event listener for the message event, or it can define the onmessage handler to listen for any messages sent by the parent thread.
* postmessage
Pass a message to the worker.
* close()

Terminating Workers -
Workers are resource-intensive; they are OS-level threads. Therefore, you do no want to create a large number of worker threads, and you should terminate the web worker after it completes its work. Workers can terminate themselves, like this: self.close();
Reference: HTML DOM addEventListener() Method; The Basics of Web Workers

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
KyryIx
5 years, 5 months ago
Not exists "close" method, but "terminate" method in Web Worker API: https://developer.mozilla.org/pt-BR/docs/Web/API/Worker Affirmation correct?
upvoted 2 times
stef1
5 years, 3 months ago
There are two ways to stop a worker: by calling worker.terminate() from the main page or by calling self.close() inside of the worker itself. So the answers are correct. See and try a working example here: https://www.html5rocks.com/en/tutorials/workers/basics/ To be 100% code-precise, the graphics is wrong in two places: Answer one should actually read: "self.addEventListener('message', function(event) {" to wrap up the whole block of the code, ending with the last line of the graphics; and the "default" switch option is obviously duplicated.
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 ...