InvokeLater function does not respect delay (ms) parameter value

Hi,
I am writing a retry logic for executing a function N number of times after delay_millisecond duration. I found through forum discussions that system.util.invokeLater function is the way to delay function execution. So, i used it.
but the problem is that the function gets executed at around 500ms while i am passing 5000ms as delay parameter value. even if I passed 500000ms it did not respect that. Execution still happened at around 400ms.
I was expecting that the execution will be delayed(kind of wait/sleep).
Please help me here. It's important to implement the retry logic the way i explained above.

invokeLater is not the solution. It's a special purpose function that is only used when you need to modify the UI from a background thread.

Explain your requirements a little more and maybe someone can help. This kind of logic is not straightforward to implement in Ignition, because generally speaking, scripts should not be blocking.

I'm guessing you are attempting this in Perspective? The examples of using invoke later for delayed actions are Vision applications.

1 Like

This is what I am doing-
I have used WebDev module to create a Endpoint using doPost method.
Inside doPost method, I accept a JSON payload, process that and put it inside a MSSQL DB table. I have written a function for that in which I check DBConnection status before attempting insert(or other DB operations). If it is Invalid, I retry N times at an interval of T seconds. I was expecting to use invokeLater function to achieve this T seconds delay in retry function execution but it is not working.
I have planned to put retry logic for other functionalities as well where execution fails the first time. So, it is important for me to get this delayed retry working.

Consider creating your own ScheduledExecutorService (using a static method from Executors) and caching it in system.util.globals.

Could you please provide sample code for this?
Everything you mentioned is very new to me.