In previous versions of AX, we could use setTimeOut() method to execute a form method periodically (actually this method belongs to Object, so any class derived from Object could benefit from it). However, this method is deprecated in AX 7 and new setTimeoutEx() is introduced to replace it.
You may find setTimeOut() in source code, but it does nothing, and probably should cause BP error or warning.
I created a sample form to demonstrate how it works. It has only one Time control that is updated each 500 milliseconds. This form is quite similar to AX 2012 tutorial_Timer but it does not exist in AX 7 anymore.
[Form] public class TestTimer extends FormRun { void run() { super(); element.setTimeoutEx(formMethodStr(TestTimer, updateTime), conNull(), 500); } public void updateTime(AsyncTaskResult _result) { if (!element.closed()) //otherwise will be executed even after form close. { TimeControl.value(DateTimeUtil::getTimeNow(DateTimeUtil::getUserPreferredTimeZone())); element.setTimeoutEx(formMethodStr(TestTimer, updateTime), conNull(), 500); } } }
When you call setTimeoutEx() method AX adds TimerControl control to a form and executes task asynchronously.
Please note two important things here:
- Method called by setTimeoutEx() should accept AsyncTaskResult as a parameter or run time exception will be thrown.
- updateTime() method checks if a form is not closed, otherwise AX will execute this code even after the form is closed.