SharedWorker Class
A shared worker (https://html.spec.whatwg.org/multipage/workers.html#shared-workers-and-the-sharedworker-interface): the SharedWorker objects of the same browsing context group with the same script URL and name (and origin) are connected to the same SharedWorkerGlobalScope, which runs on its own thread. Each object communicates with the worker through its SharedWorker.Port.
public sealed class SharedWorker : EventTargetRemarks
A shared worker lives until it calls close() or its browsing context group is disposed.
See also
- Inheritance
EventTargetSharedWorker
Constructors
| Name | Description |
|---|---|
| SharedWorker(GlobalScope, string, SharedWorkerOptions?) | Connects to a shared worker whose owner is owner (https://html.spec.whatwg.org/multipage/workers.html#dom-sharedworker). |
| SharedWorker(TrustedScriptUrl, SharedWorkerOptions?) | Connects to a shared worker, created if needed (https://html.spec.whatwg.org/multipage/workers.html#dom-sharedworker). |
| SharedWorker(TrustedScriptUrl, string) | Connects to a shared worker, created if needed (https://html.spec.whatwg.org/multipage/workers.html#dom-sharedworker). |
| SharedWorker(string, SharedWorkerOptions?) | Connects to a shared worker, created if needed (https://html.spec.whatwg.org/multipage/workers.html#dom-sharedworker). |
| SharedWorker(string, string) | Connects to a shared worker, created if needed (https://html.spec.whatwg.org/multipage/workers.html#dom-sharedworker). |
SharedWorker overloads
SharedWorker(TrustedScriptUrl, string)
Worker.csConnects to a shared worker, created if needed (https://html.spec.whatwg.org/multipage/workers.html#dom-sharedworker).
public SharedWorker(TrustedScriptUrl scriptUrl, string name)Parameters
scriptUrlTrustedScriptUrl- The URL of the script, created by a Trusted Types policy.
namestring- The name of the worker.
See also
SharedWorker(string, string)
Worker.csProperties
| Name | Description |
|---|---|
| OnError | Gets or sets the event handler of the error event. |
| Port | Gets the port connected to the connect event of the worker (https://html.spec.whatwg.org/multipage/workers.html#dom-sharedworker-port). |
OnError
Worker.csGets or sets the event handler of the error event.
Port
Worker.csGets the port connected to the connect event of the worker (https://html.spec.whatwg.org/multipage/workers.html#dom-sharedworker-port).
public MessagePort Port { get; }