Applies To:
  • CitectSCADA 5.40

Summary:
I have written code that creates a new Word document using the CreateObject() function in CitectVBA. I find that the first time I run this code Citect seems to hang for some time - I cannot even press buttons on a page. Does this mean that multi-threading does not work properly? 

Solution:
Multi-threading works in both Cicode and CitectVBA. CitectVBA supports co-operative multi-threading at the process level, which means that any single macro language instruction (in CitectVBA or Cicode) that takes a long time to execute will hang Citect for that period of time. In CitectVBA the function CreateObject() generally takes a long time to execute. In this case you are creating a word document so Citect will hang for the period of time that it takes to run up Word. Incidentally, you have the same limitations using Cicode with certain functions. For instance, try connecting to a remote data base using the Cicode SQL functions.

One way you can work around this is by creating the new Word document on startup and then use it whenever you need it. You can do this by having a single CitectVBA thread that creates the object and then runs in a infinite while loop that acts as a state machine (executes code appropriate to the state of specific tags - may make use of a SELECT CASE statement) and does all that you require of it. You can then control the state machine with variable tags that are changed under semaphore (see the SemOpen() function in the Citect Online Help).

 

Keywords:
 

Attachments