Usina BRAdvPL Guide
Sign in
← All topics
PRACTICAL GUIDEUnder review

AppServer jobs

StartJob(cName,cEnv,lWait,[parm1..parm25])

Runs a routine in a separate thread with controlled return behavior.

AppServer jobsAdvPL
01 · OVERVIEW

Overview

StartJob receives a function, environment and lWait: true waits and returns the worker result; false returns NIL without confirming processing outcome. Up to 25 extra arguments are allowed; objects and code blocks reach the target as NIL. The proposed runnable example only multiplies a number and needs no tables. The consulted community pattern covers RpcSetEnv, semaphores and logging, but its illustrative credentials, writes and callbacks are not reproduced. (Sources: refs. 1–2.)

02 · SYNTAX

Syntax

StartJob(cName,cEnv,lWait,[parm1..parm25])
03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function Ed499()
    Local uResult
    // Pure worker: no UI or table.
    uResult := StartJob("U_Ed499W",GetEnvServer(),.T.,3)
    ConOut(cValToChar(uResult))
Return Nil

User Function Ed499W(nValue)
Return nValue * 2
Expected result

With lWait true, the worker returns 6 for input 3. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Prepare company/branch when the worker needs data, release only its own environment and define concurrency, cancellation and idempotency.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. StartJob. TDN. Accessed on 2026-10-27.
  2. thalysjuvenal/advpl-specialist. patterns-jobs.md; commit d80599b. Accessed on 2026-10-27.
Status
Under review
Page created on
Last reviewed on
Original language
Portuguese
Reviewed by
Usina.BR
0 approved comment(s)

Comments

There are no approved comments yet.

Sign in with Google or Microsoft to comment.

Powered by Usina Docs · Alpha