Schedule and run script tasks.
Reference → Modules → Scripts → UI → Code Editor | Classes | Expressions | Monitor | References | Tasks
Scripts Tasks (Reference) are automated program units that execute in response to events or on scheduled intervals, providing the core automation logic for your FrameworX solution. ScriptTask is a self-contained code blocks that:
Unlike Script Classes, Tasks don't require method declarations - you write directly the code to be executed, similar to the contents of a method body.
| Property | Description | Required |
|---|---|---|
| Name | Task identifier used in runtime references | Yes |
| Code | Programming language (VB.NET, C#, Python) | Yes |
| Domain | Execution location: Server (default) or Client | Yes |
| Trigger | Event that initiates task execution | No |
| Period | Time interval for periodic execution | No |
| InitialState | Enabled (ready to run) or Disabled | No |
| EditSecurity | Permission level required to modify | No |
| Description | object description | No |
| Property | Description |
|---|---|
| ID | Unique task identifier |
| VersionID | Modification version counter |
| Lines | Code line count |
| BuildStatus | ? Green = Success, ? Red = Errors (Read Only) |
| BuildErrors | Compilation error count |
| BuildMessage | Compilation messages |
| Category | Task grouping category |
| LockState | Edit lock status |
| DateCreated | Creation timestamp |
| DateModified | Last modification timestamp |
Important: Script Tasks contain only the method body code - no function declarations or wrappers. The platform automatically handles method creation, exception protection, and thread management.
csharp
// Direct code - NO method declaration
double temperature = @Tag.Temperature;
if (temperature > 100)
{
@Tag.AlarmActive = true;
@Alarm.Notify("High Temperature");
}csharp
// ? WRONG - Do not include method wrapper
public void ProcessTemperature()
{
// Code here
}All solutions include predefined tasks:
Tasks execute when specific events occur:
Configure periodic execution:
When a Script Task needs to fan out work to a background thread, prefer
TK.CreateTaskEvent over directly calling
Task.Run(async () => ...).
Code launched with Task.Run from inside a Script Task runs on a thread
that has not necessarily attached to the runtime context yet. Server-loaded
properties such as @Info.Solution.SolutionName and other
@Info.* values may read as empty strings (or stale defaults) for
several hundred milliseconds - on large solutions this gap can exceed 2 seconds.
The same warning applies to any namespace whose value is populated by the runtime
context, not just @Info.*.
TK.CreateTaskEvent posts a parameter object into the named Script
Task's own event queue. The platform invokes the task body only after the host
context is ready and the property values it depends on have been resolved, so
the body can read @Info.* and similar properties without the
do-while-empty workaround.
csharp
// Inside a Script Task: package the inputs and queue an event on a target task.
var parameters = new { tableName, update };
// "Threads" is the name of an existing Script Task that does the actual work.
TK.CreateTaskEvent("Threads", parameters, false);
csharp
// Anti-pattern: launching work directly with Task.Run from a Script Task.
// The task body may execute before @Info.* properties are loaded on this thread,
// returning empty strings or stale values for hundreds of ms (more on large solutions).
tasks.Add(Task.Run(async () =>
{
// @Info.Solution.SolutionName may still be empty here.
DataTable table = await LoadTableAsync(tableName, update);
}));
csharp
public static int CreateTaskEvent(
string taskName,
object obj,
bool isSequential = true,
bool addToLast = true,
int priority = 0);
| Parameter | Description |
|---|---|
| taskName | Name of the Script Task that will receive the event. Pass the leaf name (the trailing segment after the last . is used). |
| obj | Anonymous or named object whose fields are passed to the receiving task. Retrieve inside the task body with TK.GetTaskEvent("<taskName>"). |
| isSequential | When true, the event runs only after the previously queued event for this task finishes. When false, events for this task may interleave on the thread pool. |
| addToLast | When true, append to the tail of the queue; when false, insert at the head. |
| priority | Thread priority. 0 = Normal, 1 = AboveNormal, 2 = Highest. |
| Return value | Meaning |
|---|---|
| 0 | Event queued. |
| 1 | Client-domain Script Tasks cannot create events; call from a server-domain task. |
| 2 | Script Task Server is not running. |
When the Task.Run pattern is fine. Pure CPU-bound work that
does not touch @Info.*, @Tag.*, or other runtime-context-loaded
values can still use Task.Run. The hazard is specifically reading runtime
properties from a thread the platform has not yet bound to the runtime context.
Default Configuration: Client-side tasks are disabled by default in Solution Settings because web clients don't support them yet. Most solutions use only server-side tasks.
Server Domain (Default):
Client Domain (When Enabled):
Access task runtime information via @Script.Task namespace:
csharp
// Access task properties
int count = @Script.Task.MyTask.ExecutionCount;
TimeSpan cpu = @Script.Task.MyTask.LastCPUTime;
bool enabled = @Script.Task.MyTask.Enabled;
// Control task execution
@Script.Task.MyTask.Run(); // Force execution
@Script.Task.MyTask.Enabled = false; // Disable task| Property | Type | Description |
|---|---|---|
ExecutionCount | Integer | Number of executions |
LastCPUTime | TimeSpan | CPU time of last execution |
Disable | Boolean | Task disable state |
IsRunning | Boolean | Currently executing |
LastError | String | Last execution error |
csharp
// Direct access to Script Classes
var result = @Script.Class.Calculations.Process(100);csharp
// All namespaces available
@Tag.Temperature = 25;
@Alarm.Reset("Area1");
var data = @Dataset.Query("SELECT * FROM Production");
@Display.MainScreen.Open();vbnet
' Use Exit Function to stop execution
If temperature > 100 Then
Exit Function
End Ifcsharp
// Use return to stop execution
if (temperature > 100)
{
return;
}python
# Standard Python syntax
if temperature > 100:
returnTask not executing:
Performance issues:
Compilation errors: