NAS with multiple timers

ta5ta5 Member Posts: 1,164
Hello

I have a strange issue, with is partly covered in viewtopic.php?f=23&t=8593

NAS is running a dispatcher codeunit. This codeunit is single instance and it runs a timer. On timer event, a codeunit is runned to check and proceed a queue.
This is the strange behavior: Timer starts to run. It imports a file, moves the file and writes to a log. The file name is the primary key for the log entry. File names are always unique, as the names are given by the source system. While the first event of Timer is still running, the timer seems to be triggered again, and it tries to import the same file again. The error message is "Record xy in Table xy already exists". Also strange: To avoid such a problem, the first statement on the Timer event is to disable that event, the last statement on the timer event is to enble it again.
I can reproduce the error when I run the dispatcher code unit from a client, so it's not a special NAS problem.

Anybody can imagine a possible problem?
Thanks in advance.
Thomas

Comments

  • ara3nara3n Member Posts: 9,256
    I don't think there would be any possible problem with that provided that you are catching any errors and start the timer at the end no matter what. That's how Job Queue functions. It stops the timer and starts after the job has been run.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • kinekine Member Posts: 12,562
    I think that the problem is not in the timer, but in the File table refresh problem. Just search for file virtual table on this forum and you will see that you need to "refresh" the variable in specific way to see real state of the files...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ta5ta5 Member Posts: 1,164
    Thanks for your posts.

    I have further investigated:

    In the dispatcher codeunit there is a 2. timer. It seems, that the second timer stops the running functions of the first timer, but only if in the first function is using the smtp component of nav. This smtp component maybe causes the situation that the 2. timer event fires. Sounds a bit weird :? , but I had other issues with smtp and other automation controls that seemed to took the fokus a kind of away from nav for a moment. Taking the focus away for a moment causes for example form to refresh when focus is back, etc.

    What do you think? Any contributions are welcome!
    Thomas
  • DenSterDenSter Member Posts: 8,305
    Have you considered running two single instance codeunits, each with their own timer?
  • ta5ta5 Member Posts: 1,164
    DenSter wrote:
    Have you considered running two single instance codeunits, each with their own timer?

    Yes, but quite complicated to change, heavy customized.
    I made some tests with jMail, works like a charm and the licensing costs are moderate, probably cheaper than refactoring the dispatcher codeunits. Although it's not in a production environment yet, I'm optimistically to have solved/work around the problem.

    Btw: Nav smt component imho has other gui-/threading-related problems. If C/AL Message statment is used while having the component instantiated, the client crashes in a way, that the keyboard does not work anymore in the current nav session and the fin.exe needs to be killed with task manager. That's the main reason I switched to a 3rd party component in that case.

    Thomas
  • FDickschatFDickschat Member Posts: 380
    What I usually do when importing files (with a timer or manual doesn't matter) is first to move the file to an "import has started" folder or to rename them. As the file is no longer in the first folder the function could not try to import the same file a second time.

    I usually have 3 folders:
    Import (this is where new files are dropped)
    Temp (this is where the files will be moved to when the processing starts)
    Archive (this is where the files will be moved to after the import)

    I also always create a file log table which holds the import/export status of files with an option field (Not yet processed, Import/Export started, Import/Export completed). If something goes wrong then I at least know the last status of the file and in which folder it currently is.
    Frank Dickschat
    FD Consulting
Sign In or Register to comment.