Applies To:
  • CitectSCADA x.x

I am calling my C code function via the cicode DLLCall() function. My function takes a long time to execute and during this time Citect pauses. Is there a way around this problem? 

During the execution of the DLL function the cicode engine will wait until the function has completed causing Citect to pause. You may work around this by making your function take several DLLCalls to complete or use another Win32 thread and create a function to check when the original function has completed.

For example you could create MyFunction so that the first time it calls it starts the long calculation or process. However it will return to Citect and return a special result. Your cicode can check for this result and keep calling the function until the calculation is complete. With 16 bit code this is difficult as you must save and restore the function state and somehow suspend it's operation part way through the calculation. With 32 bit code you may create another thread when the function is first called and then return saying the function is pending. The new thread will call the slow function and will set the result when completed. The cicode will call a function which polls for the completion of the function and returns the result.

The cicode could look something like this:

sResult = DLLCall(hStartMyFunc, "argument");
sResult = DLLCall(hGetResultMyFunc, "");

The C DLL code could look something like this:

char sResult[128];

StartMyFunction(char* sArguments)
strcpy(sResult, "PENDING");
_beginthread(SlowFunction, 0, sArguments);

return sResult;

return sResult;

SlowFunction(char* sArguments)

do the long operation;

strcpy(sResult, sTheAnswer);