Using a Single Instance codeunit causes problems

willywilly Member Posts: 67
Hi! Thanks for the help. It seems that Codeunit 1 causes the problems. I moved the code inta a form (on open trigger) and It worked well :)
Kine: I also added the check for ISCLEAR(). Thank you


Hi! I am testing a little codeunit which is supposed to be triggered once per minute.
I have made a single instance codeunit and calls it in codeunit 1 when logging in.
If I use av Native database ( version 4.0 sp1) It all works great, but if I do the same on SQL, I get a number of errors when changing company or trying to exit the database.
(Error in module xxxx, appears a couple of times ).

Do some of you know what I am doing wrong or can I do it differently?

// Here is the code :
OBJECT Codeunit 70088 TEST Navision Timer
{
OBJECT-PROPERTIES
{
Date=14.02.06;
Time=17:28:23;
Modified=Yes;
Version List=;
}
PROPERTIES
{
SingleInstance=Yes;
OnRun=BEGIN
IF CREATE(NavTimer) THEN
BEGIN
NavTimer.Interval(10000);
NavTimer.Enabled(TRUE);
END;
END;

}
CODE
{
VAR
NavTimer@1000000001 : Automation "{3B311C81-140E-11D5-8B18-00D0590B4EC5} 1.0:{3B311C92-140E-11D5-8B18-00D0590B4EC5}:'Navision Timer 1.0'.Timer" WITHEVENTS;

PROCEDURE TestFunction@1000000000();
BEGIN
MESSAGE('hi');
END;

EVENT NavTimer@1000000001::Timer@1(Milliseconds@1000000000 : Integer);
BEGIN
TestFunction();
END;

EVENT NavTimer@1000000001::TimerError@2(ErrorString@1000000000 : Text[1024]);
BEGIN
END;

BEGIN
END.
}
}

Answers

  • ara3nara3n Member Posts: 9,257
    Have you tried to add code to Companyopen and Company trigger to disable the codeunit?
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • kinekine Member Posts: 12,562
    Better is to use
      if ISCLEAR(NavTime) then     //check if the variable is created or not
       IF CREATE(NavTimer) THEN 
    

    Try to use the codeunit as local variable in the CU1, not global.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • krikikriki Member, Moderator Posts: 9,118
    Strange, I am using the 'Navision Timer 1.0'.Timer with Navision 4.0SP1 on SQL without problems.
    OnRun:
    CREATE(autTimer);
    autTimer.Interval(10000);
    autTimer.Enabled(TRUE)
    

    autTimer::Timer(Milliseconds : Integer)
    MyFunction();
    

    And all works without any problem.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • kinekine Member Posts: 12,562
    Yes, the timer is working correctly, I think that there is problem that it is called from CU1 and this can be in some cases the source of errors...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • krikikriki Member, Moderator Posts: 9,118
    Well, I never had problems with it.
    But I run the codeunit like this:
    CODEUNIT.RUN(CODEUNIT::"My Singleinstance Codeunit");
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.