invokeLater in Expession binding

I have a template which has approximately 20 internal properties. Each property has a expression binding. It is either reading a value from a tag or calling a script(using runScript) to get its value. Functions being called in runScript use some of the other properties as parameters.

A window which has the this template’s instance takes up to 20 second to open. After opening initially it shows tag binding error icon which disappears in couple of seconds.

Is there any way this delay can be reduced? Is invokeLater function is useful in this case and can it be called in expression binding? or is there any other approach to minimize the delay?

Have you considered wrapping the expressions that cause the binding errors with the try() function? That way you can force it to default to a set value whilst it is calculating.

1 Like

There’s a fair amount of overhead using runScript (or my objectScript). Consider using a single runScript call supplying all necessary parameters to return a dataset with columns for each of the twenty calculated template parameters. Elsewhere in the template use try({TemplateName.DatasetParam}[0,'myParam'], startupDefault) instead of {TemplateName.myParam}.

1 Like

Also, don’t make database calls or tag reads or any other calls that require a gateway round-trip. Do all of that kind of stuff with the appropriate asynchronous bindings and feed the results to runScript as extra parameters.

Just to tack on to @pturmel , as a general rule, it’s good design and more optimal to make as minimal calls to the database as possible. If you have 20 internal properties each with their own database request - now say you need to manually refresh them - thats 20 lines of code. If you could do it in one database and use the try() technique he mentions, now if you need to refresh the whole scree, its only a single line of code.

Alternatively, if you have it at a polling rate instead of coded refreshes, you’ve just cut your number of database requests by 95% going from 20 calls to 1.

Thanks for your reply.
I am not sure if I understand what asynchronous binding is. Could you please cite an example? E.g. to read a tag, what should I use to get a tag value instead of tag(tagPath) in expression binding?

Use direct and indirect tag bindings on additional custom properties. If you are using the tag() function anywhere other than a gateway expression tag, you are screwing up. Tag bindings and query bindings do their work on background threads, leaving the user interface thread (Java Swing is single-threaded) alone until they have results to deliver. Expression bindings, including bindings involving tag() and runScript() and objectScript(), must run on the user interface thread since they return a value to the binding, and property values must be delivered on the UI thread. (Swing requirement.)