CitectVBA Programming Reference > Integrating CitectVBA into your project > Multithread Considerations with CitectVBA

Multithread Considerations with CitectVBA

Cicode is pre-empted and executed on an instruction-by-instruction basis. This means that execution of a simple unnested Cicode thread can only switch to another thread after the current Cicode instruction has completed execution.

CitectVBA code is pre-empted and executed on a line-by-line basis (as opposed to an instruction-by-instruction basis), and pre-empting can only occur after the current line has completed execution.

Each line of CitectVBA script is handled as a separate thread in CitectSCADA. Therefore multiple procedures placed on one line may not complete before another subsequent thread is processed in a multithreading environment. This could cause unpredictable results and consequences, including data invalidation and corruption.


  • Create your CitectVBA program so that every code statement is positioned on a unique line.
  • Do not group more than one code statement on a single line in your program. Grouping CitectVBA statements on a single line can cause data corruption during multithreaded execution.

Failure to follow these instructions can result in death, serious injury, or equipment damage.

If, for example, you were reading or setting some variable or point in a multi-statement thread, and further processing that data in a later thread,that data might become invalid or incorrect. For this reason, you should separate every statement onto separate lines in CitectVBA.

For example, it is better to write:

A = Motor1.speed() + Motor4.speed() + Motor5.speed()


A = Motor1.speed()
A = A + Motor4.speed()
A = A + Motor5.speed()

in situations where the method speed()may take a long time to execute.

In the first example above, the CitectVBA thread executes for three times longer before it can be pre-empted than in the latter example.

Note: This does not apply to Cicode because the Cicode engine can pre-empt aggregated code.

See Also

Accessing Cicode Tags with CitectVBA

Using CitectVBA in CitectSCADA Command or Expression fields

Calling CitectVBA from Cicode

Calling Cicode from CitectVBA