Hello Dojo,
I know that when we use static objects in connectors they are shared between all elements running that connector, and if we use non-static objects, each element gets it's own instance of the object that lives until element is stopped/restarted.
I'm wondering about this life cycle of objects in automation scripts context.
- When are objects created and destroyed in automation script? If I run same script 10 times, with static properties, do I have to initialise them each time?
- If I do have to initialise them each time, is there a way to share objects across multiple runs of the same script?
- Is there a difference between static and non-static objects in AS context, from DataMiner perspective(not including differences that come from .NET itself)?
- Is there a difference between scripts defined as libraries and those that aren't?
Thank you,
Cheers
Hi Edib,
Automation scripts are run as part of the SLAutomation process. As such, the life cycle of objects in a script respects the life cycle of C# objects in a project, where you can see each script almost as a class in that process.
To answer your specific points:
- Static objects are created in the first script execution and will live while SLAutomation runs and the script has not been edited. Normally this process only stops when DataMiner stops but since it is not a critical process it may crash and start back up without DataMiner restarting at which point objects will need to be initialized again.
So if you run the same script on the same DataMiner agent 10 times, the static objects will only be initialized once.
If you modify the script then it will reinitialize all static objects. - They are only initialized once and the static object should remain in memory across multiple executions on the same DataMiner agent, keep in mind that a script may execute on a different agent where the object will not necessarily have the same content in memory.
If you just need basic memory persistence then a static object should be enough but if you want 100% guaranteed "survival" and synchronization of data then you should not rely on static objects and you should use a saved parameter on an element or something similar - Same as regular C# and .NET, DataMiner just executes the code with access to the helper objects like the Engine class | DataMiner Docs
- Not too familiar with the libraries part but I would say it follows the same rules.