Announcement

Collapse
No announcement yet.

OnTimer Application Exit problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • OnTimer Application Exit problem

    Hi, I need a timer to close my application after an hour so 3600000 ms.
    I tried timers of all types including Global Timer Plugin, that I don't understand anyway.
    My application has 5 pages, so jumping through the pages will restart the timer.

    How I can exit on timer without problems?
    Really thanks!

  • #2
    This will check your application's lapsed CPU time every minute, and then close your application at 60 minutes ...

    Globals
    Code:
    i = os.clock()
    Page On Show (for each page)
    Code:
    Page.StartTimer(60000, 10);
    Page On Timer (for each page)
    Code:
    lapsed_secs =   os.clock() - i 
    if lapsed_secs > 3600000 then
        Application.Exit(0);
    end

    Comment


    • #3
      Edit,

      Oops, sorry - that's not quite correct. Lapsed CPU time gets measured in seconds (not millisecs) - so '3600000' should actually be adjusted to '3600' in the above example. And depending on how accurately you want things timed, you can also lose the variable from Globals, and instead just go with:

      Page On Show (for each page)
      Code:
      Page.StartTimer(60000, 10);
      Page On Timer (for each page)
      Code:
      i = os.clock();
      if i > 3600 then
          Application.Exit(0);
      end
      So that fires each page timer every minute and shuts the application once elapsed CPU time has reached 3600 seconds (1 hour).

      Comment


      • #4
        hello bio, how to reset the os.clock() to zero() if the time is reach?

        Comment


        • #5
          @BioHazard
          Thanks for the fast reply, I will try this new solution.
          Hope i works!

          Comment


          • #6
            Originally posted by telco View Post
            hello bio, how to reset the os.clock() to zero() if the time is reach?
            You don't reset os.clock() per se. It's a native Lua function which returns the number of seconds the CPU has been engaged by a given process. And resets to zero only after the process has been terminated. So instead, you'd write a count function and assign a dynamic variable to reset to zero at defined interval/s.

            Comment


            • #7
              Originally posted by AndrewX View Post
              ... My application has 5 pages, so jumping through the pages will restart the timer. How I can exit on timer without problems?
              The os.clock() method posted above will work on multi-page apps, no problem. Is probably also the simplest & most concise method.

              But you can use other methods across multiple pages, too. It doesn't matter that the timer gets restarted on page jumps - because values carry across pages, providing they're stored in global variables (all AMS variables are global in nature unless specified as local).

              Attached is an example which demonstrates. This one uses a simple count-action to instruct the application when to close. Note how the variables are global in nature and carry their values across pages. Also, be sure to label the page timer correctly from each Page On Show event. (This example is set to close the application at '10' seconds. Just swap the relevant value for '3600' seconds if you want it to close after one hour).


              Attached Files

              Comment


              • #8
                telco,

                Addendum to previous ...

                Originally posted by telco View Post
                hello bio, how to reset the os.clock() to zero() if the time is reach?
                Attached for you is an example demonstrating how to reset a count to 'zero' at any predefined interval. (Uses a simple count-action attached to a dynamic variable). This is what you would use, not the os.clock() function.
                Attached Files

                Comment


                • #9
                  Edit,

                  AndrewX
                  telco

                  Minor typos in above examples. (LOL, really must stop writing code when I'm tired).
                  Use these corrected versions instead:
                  Attached Files

                  Comment


                  • #10
                    Dear BioHazard, THANK YOU SO MUCH!
                    As usual, simple example, simple solution.
                    Very appreciated!

                    Only if you have time, how could this code operate a countdown?
                    From 10 seconds to 0 seconds time out, now it starts from 0 to 10 seconds.

                    I repeat, only if you have time.

                    Comment


                    • #11
                      Just simple maths
                      Code:
                      Globals
                      nCount = 10;
                      
                      OnTimer
                      nCount = nCount - 1;
                      Paragraph.SetText("counter", nCount);
                      Paragraph.SetText("subheading", "Time Accrued:");
                      Audio.Load(CHANNEL_BACKGROUND, "AutoPlay\\Audio\\beep.wav", true, false);
                      
                      if nCount == 0 then
                          Paragraph.SetText("subheading", "Time Is Up!");
                           Audio.Load(CHANNEL_BACKGROUND, "AutoPlay\\Audio\\timeup.wav", true, false);
                           nCount = 10;
                      end

                      Comment


                      • #12
                        Originally posted by charliechaps View Post
                        Just simple maths
                        Good job, thanks for the suggestion.

                        Comment


                        • #13
                          I found an issue.
                          If I insert in the project a DialoEx, with the same Page code OnShow and On Timer, using DialogEx.StartTimer instead of page.StartTimer, all blocks!

                          Comment


                          • #14
                            try this
                            Simple Countdown Timer with Sound Effects.apz

                            Comment


                            • #15
                              Thanks for the suggestion but it seems doesn't solve my problem. I don't need another timer, I need dialogEx behavior the same as the page.

                              On each page I've

                              OnShow
                              Code:
                              Page.StartTimer(1000, 30);
                              OnTimer
                              Code:
                              nCount = nCount - 1;
                              if nCount == 0 then
                              Application.Exit(0);
                              end
                              OnGlobals I've
                              Code:
                              ---Countdown 20 sec for testing
                              nCount = 20;


                              Comment

                              Working...
                              X