# InvokeLater function does not respect delay (ms) parameter value

**URL:** <https://forum.inductiveautomation.com/t/invokelater-function-does-not-respect-delay-ms-parameter-value/76890>\
**Category:** Ignition\
**Created:** [July 25, 2023, 5:48pm UTC](https://forum.inductiveautomation.com/t/invokelater-function-does-not-respect-delay-ms-parameter-value/76890 "2023-07-25T17:48:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ajay\_Gupta](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@Ajay\_Gupta](https://forum.inductiveautomation.com/u/Ajay_Gupta)\
**Post date:** [July 25, 2023, 5:48pm UTC](https://forum.inductiveautomation.com/t/invokelater-function-does-not-respect-delay-ms-parameter-value/76890/1 "2023-07-25T17:48:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [July 25, 2023, 5:52pm UTC](https://forum.inductiveautomation.com/t/invokelater-function-does-not-respect-delay-ms-parameter-value/76890/2 "2023-07-25T17:52:19Z")

</div>

`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.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [July 25, 2023, 6:09pm UTC](https://forum.inductiveautomation.com/t/invokelater-function-does-not-respect-delay-ms-parameter-value/76890/3 "2023-07-25T18:09:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ajay\_Gupta](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@Ajay\_Gupta](https://forum.inductiveautomation.com/u/Ajay_Gupta)\
**Post date:** [July 25, 2023, 6:46pm UTC](https://forum.inductiveautomation.com/t/invokelater-function-does-not-respect-delay-ms-parameter-value/76890/4 "2023-07-25T18:46:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 25, 2023, 6:55pm UTC](https://forum.inductiveautomation.com/t/invokelater-function-does-not-respect-delay-ms-parameter-value/76890/5 "2023-07-25T18:55:58Z")

</div>

Consider creating your own [`ScheduledExecutorService`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/concurrent/ScheduledExecutorService.html) (using a static method from [`Executors`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/concurrent/Executors.html)) and caching it in [`system.util.globals`](https://docs.inductiveautomation.com/display/DOC81/system.util.getGlobals).

---

<div class="post-metadata">

**Author:** ![Ajay\_Gupta](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@Ajay\_Gupta](https://forum.inductiveautomation.com/u/Ajay_Gupta)\
**Post date:** [July 25, 2023, 7:52pm UTC](https://forum.inductiveautomation.com/t/invokelater-function-does-not-respect-delay-ms-parameter-value/76890/6 "2023-07-25T19:52:33Z")

</div>

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