Class Worker
- Namespace
- CSharpToJavaScript.APIs.JS
- Assembly
- CSharpToJavaScript.dll
The Worker interface of the Web Workers API represents a background task that can be created via script, which can send messages back to its creator.
[Value("Worker")]
public class Worker : EventTarget, AbstractWorker, MessageEventTarget
- Inheritance
-
Worker
- Implements
- Inherited Members
Remarks
Creating a worker is done by calling the Worker("path/to/worker/script") constructor.
Workers may themselves spawn new workers, as long as those workers are hosted at the same origin as the parent page.
Note that not all interfaces and functions are available to web workers. See Functions and classes available to Web Workers for details.
-Using Web Workers
-Functions and classes available to Web Workers
-Other kind of workers: SharedWorker and Service Worker.
-OffscreenCanvas interface
Constructors
Worker()
public Worker()
Worker(Union96, WorkerOptions)
The Worker() constructor creates a Worker object that executes the script at the specified URL. This script must obey the same-origin policy.
public Worker(Union96 scriptURL, WorkerOptions options = null)
Parameters
scriptURLUnion96optionsWorkerOptions
Remarks
NOTE
There is a disagreement among browser manufacturers about whether a data URL is of the same origin or not. Though Firefox 10 and later accept data URLs, that's not the case in all other browsers.
The Worker interface it belongs to.
Methods
PostMessage(dynamic, StructuredSerializeOptions)
The postMessage() method of the Worker interface sends a message to the worker. The first parameter is the data to send to the worker. The data may be any JavaScript object that can be handled by the structured clone algorithm.
[Value("postMessage")]
public GlobalObject.Undefined PostMessage(dynamic message, StructuredSerializeOptions options = null)
Parameters
messagedynamicoptionsStructuredSerializeOptions
Returns
Remarks
The Worker postMessage() method delegates to the MessagePort PostMessage(dynamic, List<Object>) method, which adds a task on the event loop corresponding to the receiving MessagePort.
The Worker can send back information to the thread that spawned it using the PostMessage(dynamic, List<Object>) method.
-The Worker interface it belongs to.
PostMessage(dynamic, List<Object>)
The postMessage() method of the Worker interface sends a message to the worker. The first parameter is the data to send to the worker. The data may be any JavaScript object that can be handled by the structured clone algorithm.
[Value("postMessage")]
public GlobalObject.Undefined PostMessage(dynamic message, List<Object> transfer)
Parameters
Returns
Remarks
The Worker postMessage() method delegates to the MessagePort PostMessage(dynamic, List<Object>) method, which adds a task on the event loop corresponding to the receiving MessagePort.
The Worker can send back information to the thread that spawned it using the PostMessage(dynamic, List<Object>) method.
-The Worker interface it belongs to.
Terminate()
The terminate() method of the Worker interface immediately terminates the Worker. This does not offer the worker an opportunity to finish its operations; it is stopped at once.
[Value("terminate")]
public GlobalObject.Undefined Terminate()