Which trigger gets fired when NAS is shut down?

havhav Member Posts: 299
Hi,
I am using a custom COM component which provides methods such as Initialize(), Synchronise() and Terminate(). The Initialize() method connects to a database of a 3rd party application whereas the Terminate() method disconnects from that database. The Synchronise() method synchronises all updates to related tables between NAV and 3rd party databases.
I have written a codeunit with functions such as Init() that wraps the Initialize() method, Synch() that wraps the Synchronise() and Term() that wraps the Terminater() method of the COM automation server. The Sychronise() function is called from the OnRun() trigger of the codeunit.
I have setup a jobqueue for this codeunit such that it gets scheduled at every 2 min interval.
I know that when NAS is started, it calls the NASHandler() trigger of the codeunit 1 only once. I have setup my startupparameter of NAS as JOBQUEUE so the handler calls the Job Queue Dispatcher codeunit.
What i want to do is that when my codeunit is scheduled for execution, the Init() should be called only once at the beginning, the Synchronise() should be called at every 2 min interval and the Term() should be called only once at the end.
To achieve this,
I called Init() from the OnRun() trigger of Job Queue Dispatcher codeunit. This makes connection to the 3rd party database and is executed only once.
When the NAVTimer event is raised, the Synchronise() gets called from the OnRun() trigger of my codeunit. This causes the synchronisation of both databases and is executed at every 2 min interval which is fine.
Now i want to call Term() so that the connection to 3rd party database gets closed when NAS is shut down. However i do not know where to put this call since i am unable to find which trigger gets fired when NAS is closed.
If i put Init() followed by Synchronise() followed by Term() all in the OnRun() trigger of my codeunit, it connects and disconnects to 3rd party database at each 2 min interval which is not good.
So can anyone have any idea how to trap the shut down event of NAS?
or do you have any other suggestion to handle my use-case?

Regards,
Hemant
Regards,
Hemant
MCTS (MB7-841 : NAV 2009 C/SIDE Solution Development)

Answers

  • havhav Member Posts: 299
    I have got it.
    I placed messages at several places and i found the following:-
    When NAS is started it calls NASHandler() function of CU1.
    After this it calls CompanyOpen() function to login and open the company.
    When NAS is shut down it calls CompanyClose() function to logout and close the company.

    So my problem is solved :D
    I will now call Init() within CompanyOpen() and Term() within CompanyClose() so that both initialization and termination takes place only once.
    Regards,
    Hemant
    MCTS (MB7-841 : NAV 2009 C/SIDE Solution Development)
  • kinekine Member Posts: 12,562
    Of course, there could be "crash" in NAS and than no code is called... it means sometime the NAS just ends without calling your code, you need to count with it (and e.g. use Dispose on your class to release the resources).
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • havhav Member Posts: 299
    I am using ATL COM and my class definition includes FinalRelease() method which hopefully should cleanup all resources.
    Regards,
    Hemant
    MCTS (MB7-841 : NAV 2009 C/SIDE Solution Development)
Sign In or Register to comment.