What it does
A Core background-work component; JavaScript can inspect its status and flags.
This is a component tray service. It appears below the form and does not take a canvas rectangle.
Set it up
- Add BackgroundWorker from Toolbox.
- Set its Name to
samplefor the examples below. Names are case-sensitive. - Configure the component-specific properties below.
- Open the Events inspector to add a handler: methods go in event.js, imports and subscriptions in script.js. Right-click View Events or View Script to edit either file. Use View CSS for scoped styles and View Custom Properties for JSON values.
- Save sources, save the project, and open a fresh Preview. Scripts execute in Preview.
JavaScript example
These examples use supported inline subscriptions for brevity. The Events inspector can generate separate class methods in event.js instead.
isBusy is read-only. JavaScript can configure workerReportsProgress and workerSupportsCancellation, but cannot launch a Core worker delegate. In C# call RunAsync and CancelAsync.
const busy = forma.bind("sample", "isBusy");
busy.subscribe(value => console.log("Worker busy:", value));
Component properties
| Field | Inspector key | Editor | Accepted values / range | Runtime key |
|---|---|---|---|---|
| Report progress | workerReportsProgress | checkbox | — | workerReportsProgress |
| Cancellation | workerSupportsCancellation | checkbox | — | workerSupportsCancellation |
| Busy (read-only) | isBusy | checkbox | — | isBusy |
Runtime property API
Use forma.get("sample", key), forma.set("sample", key, value), or forma.bind("sample", key). Read a binding with .value; write only when the Binding column permits it. Numbers and booleans must keep their types. Arrays are passed directly, not as JSON strings.
| Key | Value type | get | set | Binding | Meaning / restrictions |
|---|---|---|---|---|---|
text | string | Yes | Yes | Read/write | Display text; use value to read live text input. |
enabled | boolean | Yes | Yes | Read/write | Enabled |
visible | boolean | Yes | Yes | Read/write | Supported runtime property. |
tag | string | Yes | Yes | Read/write | Tag |
workerReportsProgress | boolean | Yes | Yes | Read/write | Report progress |
workerSupportsCancellation | boolean | Yes | Yes | Read/write | Cancellation |
isBusy | boolean | Yes | — | Read-only | Worker status; read-only. |
Set commands cross the native bridge asynchronously. An immediate get after set may return the previous value. Observe a binding or use the assigned value locally. Getter arrays are copies. Geometry is configured model geometry; layout and CSS may override rendered bounds.
Shared inspector fields
| Field | Inspector key | Editor | Accepted values / range | Runtime key |
|---|---|---|---|---|
| Name | name | text | — | Designer only |
| ID (read-only) | id | text | — | Designer only |
| Text / Title | text | text | — | text |
| Tag | tag | text | — | tag |
| Locked | locked | checkbox | — | Designer only |
| Enabled | enabled | checkbox | — | enabled |
Events and lifecycle
Component hooks: Relevant DOM events and shared lifecycle events. Core worker events are not automatic JavaScript callbacks.
Tray services have lifecycle events even without a visible control. Event names are case-insensitive. Put handlers on the component producing the event; a Timer Tick handler belongs to the Timer, or can be observed through forma.root.on("Tick", handler). See the event guide for payloads, validation, cleanup, and startup order.
Property-change payload
All components can report PropertyChanged for changed projected runtime properties. Handlers expose source/subscriber component handles; native DOM targets remain available. Input/Change can supply typed property values, while Click normally supplies identity without a property/value pair.
forma.on("PropertyChanged", ({ source, property, value, previousValue, origin }) => {
console.log(source.name, property, previousValue, "→", value, origin);
});
Use forma.root.on(...) to observe the active form, and event.toJSON() for portable logs. Subscriptions return unsubscribe and are cleaned up with the subscribing script.
C# example
Use this in a configured Forma C# host, not in script.js. The renderer is your host's WebView2Renderer instance.
using var sample = new Forma.Core.Controls.BackgroundWorker
{
Name = "sample"
};
await renderer.RenderAsync(sample);
C# model reference
These are Core constructor defaults, not necessarily the Builder’s drop-time styles or size. Appearance fields belong to Builder Appearance. C# events are not all forwarded to JavaScript.
| Property | C# type | Constructor default | Writable |
|---|---|---|---|
IsBusy | Boolean | false | No |
WorkerReportsProgress | Boolean | true | Yes |
WorkerSupportsCancellation | Boolean | true | Yes |
Name | String | null | Yes |
LayoutSlot | Int32 | 1 | Yes |
X | Nullable1` | null | Yes |
Y | Nullable1` | null | Yes |
Text | String | null | Yes |
Value | String | null | Yes |
Placeholder | String | null | Yes |
Label | String | null | Yes |
ControlType | String | "backgroundworker" | No |
Core methods: RunAsync(work), CancelAsync(), Dispose(), GetRenderState(), HandleRuntimeEvent(runtimeEvent), Add(child), Insert(index, child), MoveChild(child, index), Remove(child).
Core events: ProgressChanged, RunWorkerCompleted, ChildAdded, ChildRemoved, PropertyChanged.