Standards-based Web Workers are supported for multithreaded JavaScript apps. Web Workers can improve the responsiveness of their UI thread. Web Workers can use the postMessage function to communicate with the UI thread.
This example uses two Web Workers to calculate prime numbers. Even though this task is CPU intensive, the UI remains responsive because of the web workers.
Calculate Primes
Code running in a Web worker has access to the <b> setTimeout </ b> and <b> setInterval </ b> methods. These methods can be used to throttle long running scripts or for other general purposes timing. Click the buttons to instruct the worker to set
a timeout or interval timer. At each callback of the timer, the Web Worker posts messages Which are then Displayed by the example.
Web Workers therefore support channel messaging. Channel Messaging can be used to enable direct communication between workers. In this Example, the UI thread Creates two workers and a set of ports through Which the Web Workers can communicate Directly. The
UI thread then passes the string "Hello World" to the first Web Workers, Which passes it on to the second Web Workers via the specified port, Which then passes it back to the UI thread.
One finds the example below
[Lnk "https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/WebWorkers" /]