IR
irwinrodriguez.dev
Back to docs

API Reference

Complete reference for FoxCoreClass, the Task object and the task procedure signature.

FoxCoreClass

Main FoxCore class. COM ProgId: FoxCore.FoxCoreClass. Entry point for creating and managing async tasks.

Methods

SignatureDescription
Run(lcProc AS STRING, loParams AS OBJECT) AS Task Executes lcProc asynchronously. Returns a Task object immediately. loParams can be any VFP object.
RunAll(@laProcs AS ARRAY) AS OBJECT Executes an array of procedure names in parallel. Returns an array of Task objects, one per entry.
Cancel(loTask AS Task) AS VOID Requests cancellation of loTask. The Task moves to Status="Cancelled". The task must check status to respond to cancellation.
WaitFor(loTask AS Task [, lnTimeoutMs AS NUMBER]) AS BOOLEAN Blocks until loTask finishes or lnTimeoutMs elapses. Returns .T. if the task completed, .F. on timeout. lnTimeoutMs is optional (0 = no limit).
GetActiveTasks() AS ARRAY Returns an array with all Tasks in Pending or Running state.
SetLicensePath(lcPath AS STRING) AS VOID Specifies the path where FoxCore will look for FoxCore.lic. Call before Run() if the file is not in the application folder.

Properties

PropertyTypeDescription
Version STRING Installed FoxCore version string. Read-only.
MaxWorkers NUMBER Maximum number of concurrent tasks. Default: 8. Maximum: 32.
Note on MaxWorkers: The default value of MaxWorkers is 8. The absolute maximum is 32. Each worker is an independent VFP instance; setting this too high can saturate system memory.

Task

Object returned by Run() and RunAll(). Represents an individual task and exposes its status, progress and result.

Task properties

PropertyTypeDescription
Id STRING Unique task identifier (GUID).
Status STRING Current state: Pending, Running, Done, Failed, Cancelled.
Progress NUMBER Progress 0-100. Set by the task procedure.
Result ANY Result value on completion. Set by the task procedure.
Error STRING Error message when Status="Failed".
StartedAt DATETIME Date/time when the task started executing.
FinishedAt DATETIME Date/time when the task finished (Done, Failed or Cancelled).

Event callbacks

PropertyTypeDescription
OnComplete STRING Name of procedure to invoke when Status moves to Done.
OnFailed STRING Name of procedure to invoke when Status moves to Failed.
OnProgress STRING Name of procedure to invoke each time Progress changes.

Task procedure signature

Every procedure that runs as a task must accept exactly these two parameters.

PROCEDURE MyTask(loParams AS OBJECT, loTask AS OBJECT)
    * loParams -- data passed from Run() by the caller
    * loTask   -- the Task object: set Progress and Result here
    loTask.Progress = 50
    loTask.Result   = "my result value"
ENDPROC

Status lifecycle

A Task advances through the following states:

[Pending] -> [Running] -> [Done]
                      \-> [Failed]
                      \-> [Cancelled]

Next: Examples ->