Last time we have seen our “old” NTimer.dll was Microsoft Dynamics NAV 2009. It was placed in ..\Common\Microsoft Dynamics NAV\Timer.. folder.
Usually we have used it for NAS or other looping tasks.
We want to have the same in Microsoft Dynamics 2013 and later, however we see that the same doesn’t work anymore.
So how it is now?
Since Microsoft Dynamics NAV 2013 timer becomes “.NET” type in add-in’s folder. Now it is named “Microsoft.Dynamics.Nav.Timer.dll” and placed on server in C:\Program Files\Microsoft Dynamics NAV\70\Service\Add-ins\Timer.. folder.
Usage, manage and expected results are now different.
First of all this is server side timer.
We use timer as DotNet type variable like:
Timer@1000 : DotNet "'Microsoft.Dynamics.Nav.Timer, Version=18.104.22.168, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.Microsoft.Dynamics.Nav.Timer" WITHEVENTS;
Use variable in code like:
IF ISNULL(Timer) THEN BEGIN
Timer := Timer.Timer;
Timer.RedirectExceptions := TRUE;
Timer.Interval := 10000; // 10 seconds
It has two events “Elapsed” and “ExceptionOccurred” (if RedirectExceptions = TRUE).
Event “Elapsed” is executed when we want with code we want.
If we use “Timer” in NAS then code in “Elapsed” event is code we want to be executed by NAS.
And here comes big point:
If error in our C\AL code occurs then error is logged to events, NAS stops and session is terminated. We have option in NAV service config – “Retry Attempts Per Day”. Default value is 3. It means that after error occurs and NAS stops, there will be NAS restart and this will be done 3 times. If we have started NAS first time manually then after error occurs there will be 3 attempts to restart NAS. Finally we’ll have 4 errors in event viewer and need to restart NAS manually.
To avoid such situations we need move all our c\al code to codeunit and catch all errors with c\al code like:
IF NOT CODEUNIT.Run(xxx) THEN
InsertError(“A business logic error occurred: “ + GETLASTERRORTEXT);
Here in “Elapsed” event we execute some codeunit and if error during execution occurs, it is logged with some function InsertError.
Event “ExceptionOccurred” is executed when unknown exceptions like polling data from http stream causing io/timeout etc. exception comes to timer. So in this event we can log some network issues with code like:
InsertError(“A .NET exception occurred: “ + e.Exception.Message);
Where “e.Exception.Message” is error message text received by timer. This error is logged to events and, NAS stops and session is terminated. We have the same situation like in “Elapsed” event: NAS will be restarted as many times as described in config settings.
These postings are provided "AS IS" with no warranties and confer no rights. You assume all risk for your use.
Microsoft Customer Service and Support (CSS) EMEA