RunGlobalProcedureAsync
This function executes a global procedure asynchronously, in its own thread, so that it does not slow down or interfere with other running scripts. The procedure is run on the project server, but it can be called by any local or remote client.
Function | Group | Execution | Windows | Embedded | Thin Client | Mobile Access |
---|---|---|---|---|---|---|
RunGlobalProcedureAsync | Module Activity | Asynchronous | Supported | Supported | Not supported; see note | Not supported |
Syntax
RunGlobalProcedureAsync( strProcedureName ) RunGlobalProcedureAsync( strProcedureName, optStrArgument1, …, optStrArgumentN )
- strProcedureName
- The name of the procedure (i.e., a VBScript function or sub-routine defined in the Procedures folder) to run asynchronously.
- optStrArgument1, …, optStrArgumentN
- Values that are passed to the procedure’s parameters. Arguments must be passed as strings.
Returned value
Value | Description |
---|---|
-1 | Function is not supported on Viewer / Web Thin Client. |
-2 | Invalid number of parameters. You must specify at least the procedure name. |
-3 | Maximum number of threads exceeded. See note. |
-4 | Failed to compile VBScript parameters for execution. |
-5 | Failed to start the thread execution. |
-100 | Internal error. Please contact technical support. |
Notes
It is very important to note that this function can only be called by background tasks (e.g., Math, Script, Scheduler) on the project server. It cannot be directly called from any project client, even if the project client is running on the same workstation or device as the project server, because the client process is single-threaded. To indirectly call the function from a project client, configure a Math or Script worksheet to execute on a tag/expression trigger, and then configure a project screen to activate the trigger when needed. For example, configure the worksheet to execute when the value of MyTag is 1, and then configure a Button screen object to toggle the value of MyTag when pressed.
[Script] MaxAsyncThreads=8
The default number of threads is 8, but the only real limit is determined by the available system resources. Increasing the number of threads may decrease runtime performance.
Examples
Function AddMe(intNumber) If intNumber >= 6 Then AddMe = 0 Else AddMe = intNumber + 2 End If End Function
…the procedure is run by calling the RunGlobalProcedureAsync function…
RunGlobalProcedureAsync( "AddMe", "2" )
…and the function returns a thread ID that can be used with the RunGlobalProcedureAsyncGetStatus function.