NodejsEnvironment class
A Node.js runtime environment with a dedicated main execution thread.
C#
public sealed class NodejsEnvironment : IDisposable
Public Members
name | description |
---|---|
ExitCode { get; } | Gets the exit code returned by the environment after it is disposed, or null if the environment is not disposed. |
IsDisposed { get; } | Gets a value indicating whether the Node.js environment is disposed. |
SynchronizationContext { get; } | Gets a synchronization context that enables switching to the Node.js environment's thread and returning to the thread after an await . |
event UnhandledPromiseRejection | Event raised when there is an unhandled promise rejection in the Node.js environment. |
Dispose() | Disposes the Node.js environment, causing its main thread to exit. |
GC() | Runs garbage collection in the JS environment. |
Import(…) | Imports a module or module property from JavaScript. |
ImportAsync(…) | |
Post(…) | Runs an action on the JS thread, without waiting for completion. (2 methods) |
Run(…) | Runs an action on the JS thread, and waits for completion. |
Run<T>(…) | Runs an action on the JS thread, and waits for the return value. |
RunAsync(…) | Runs an action on the JS thread, and asynchronously waits for completion. |
RunAsync<T>(…) | Runs an action on the JS thread, and asynchronously waits for the return value. |
StartInspector(…) | |
StopInspector() | |
const NodeApiVersion | Corresponds to NAPI_VERSION from js_native_api.h. |
explicit operator | |
implicit operator | |
class UnhandledPromiseRejectionEventArgs | Event args for an unhandled promise rejection in a Node.js environment. |
Remarks
Multiple Node.js environments may be created (concurrently) in the same process. Each environment instance has its own dedicated execution thread. Except where otherwise documented, all interaction with the environment and JavaScript values associated with the environment MUST be executed on the environment's thread. Use the SynchronizationContext
to switch to the thread.