Announcement

Collapse
No announcement yet.

Checking the timer after PC's midnight jump

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

  • Kev Peel
    replied
    It may if you are running the timers concurrently, which you are not. So you should be safe Of course, my evidence is anecdotal, but I have come across problems with multiple timers (> 10) before. It made the system lag badly on Win9X/ME systems, probably due to the "fake" multi-tasking those versions perform. Not sure about NT-class (NT4/2000/XP/Vista) systems, as I didn't test them at the time.
    Last edited by Kev Peel; 12 Feb 2008, 09:37 PM.

    Leave a comment:


  • Heinz Grandjean
    replied
    I need every timer for only one single action.
    After the change of myVAR the timer is set mostly only to (2 to 40) sec. and after recieving the according WM_TIMER-message the myVar is reset and the timer killed.
    I tested it with more than 100 timers working simulaneously and there was no delay or any problem I could detect????
    Greetings
    Heinz Grandjean

    Leave a comment:


  • Kev Peel
    replied
    There may not be a visible or documented limit, but timers certainly are a resource hog. Try not to use more than a couple in an app.

    If you need timers for different intervals, set one timer for the minimal interval required and use STATIC or GLOBAL counter variables to execute each event every so many WM_TIMER iterations. So, in effect, Windows will only have to allocate one timer, and your (efficient) code does the rest.

    Leave a comment:


  • Michael Mattias
    replied
    I don't know that there is any limit. I've certainly never hit one

    You could write a test program to see what happens...
    Code:
    FOR Z = 1 to a lot 
      iTimer = SetTimer ( BYVAL %NULL, Z, 500, CODEPTR(TimerProc))
      IF ISFalse iTimer THEN 
         MSGBOX "Can't create timer number " & FORMAT$(Z) 
         EXIT FOR
      END IF     
    NEXT
    ....

    Leave a comment:


  • Heinz Grandjean
    replied
    Just another short "How"-question

    Hello community,

    as far, as I have seen: RtlTimeToSecondsSince1970 doesn't work
    under WIN98.
    Mr. Mattias solution according the SetTimer() works okay.

    The question:
    I understood that timers are limited objects.
    How many timers could be associated with one process simultaneously?

    Thanks and Greeting
    Heinz Grandjean

    Leave a comment:


  • Arthur Gomide
    replied
    RtlTimeToSecondsSince1970 may help

    Leave a comment:


  • Michael Mattias
    replied
    When you explain the "what" (do something periodically) instead of simply asking for help with a predetermined "how" (use TIMER) you will get lots of good ideas.

    Leave a comment:


  • Heinz Grandjean
    replied
    @ Mr. Drake: Thank you, I understand, the PC(s) are always switched on and off with the purpose of running that application; I forgot to express that.
    @Mr. Mattias: Oh, Yes, WM_TIMER is an alternative. Thanks for showing me the correct way.
    The application uses WM-Timer messages (by using SetTimer()) to process flashing indications inside the GUI's "control panel".
    I'll test it and give a short feedback.

    Greetings
    Heinz Grandjean

    Leave a comment:


  • Adam J. Drake
    replied
    49.7 days is not a limitation of how long your app runs, but how long your computer has been booted up. If you leave it on all the time, you will encounter that reset.

    Leave a comment:


  • Michael Mattias
    replied
    after checking a certain ellapse of time (depends on individual settings: 10 sec. 20 sec. or longer) sends a corresponding command to the item and after that resets the item's timeVar.
    Summing it up: it seems to be only a simple timing task.
    SetTimer() ==> WM_TIMER message (or call a callback function) every "interval" , do your thing each time.

    ????

    MCM

    Leave a comment:


  • Heinz Grandjean
    replied
    Hello Mr. Mattias,
    I' ll try to answer.
    The programme is a "real-time-application" controlling hardware-devices outside the computer. The amount of them can go up to 2.000 .
    Each item gets commands from the applications main-thread: like set or reset position, like lock or unlock state and so on.
    Each command is time-sensitive. A second thread is always controlling each item's individual TimeVar and and after checking a certain ellapse of time
    (depends on individual settings: 10 sec. 20 sec. or longer) sends a corresponding command to the item and after that resets the item's timeVar.
    Summing it up: it seems to be only a simple timing task.
    The whole application is embedded in a DDT-GUI combined with GFX-Tools.
    This works fine using PB Timer until the midnight change comes, then for some seconds it gets crazy, like I have explained above.
    Thank You for Your interest,
    Greetings,
    Heinz Grandjean

    Leave a comment:


  • Michael Mattias
    replied
    Curiously enough my current project requires me to format elapsed time.

    I do this...

    Code:
    TYPE MonitorProcParamType
        hEventReady    AS LONG      ' when thread function is launched
        ftStart        AS FILETIME  '  filetime when this starts (from GetLocalTime)
        bShowWindow    AS LONG  ' if true, the window is visible (%WS_VISIBLE set)
    .......
    
    FUNCTION... 
    
    
     LOCAL pqFT AS QUAD PTR, pqFTStart AS QUAD PTR
     LOCAL st AS SYSTEMTIME, ft AS FILETIME, elapsed AS LONG, iTime AS LONG
    
    
         ' put the start time into the parameter = current time
         ' However, I think I should be using the return from the database as the time for elapsed?
         ' elapsed time is based on this.
    
         GetLocalTime         lst
         SystemTimeToFileTime lst, mp.ftStart
    
     .....
    
              ' always update the elapsed time control
                GetLocalTime          st
                SystemTimeToFileTime  st, ft
                ' I need to get diff as quads
    
                pqFT      = VARPTR(ft)
                pqFtStart = VARPTR(@pMP.ftStart)
                Elapsed    =  (@pQFT -  @pQFtStart ) \ 1E7   ' need elapsed in seconds
               ' format elapsed time into HH:MM:SS and put on the screen..
                CALL FormatSecondsHHMMSS (elapsed) TO szText
                SetDlgItemText hWnd, %ID_JOB_ELAPSED, szText
    
    
    FUNCTION FormatSecondsHHMMSS (BYVAL ets AS LONG) AS STRING
        ' convert seconds into HH:MM:SS  string (I get elapsed converted from filetime inline)
        LOCAL hh AS LONG, mm AS LONG, ss AS LONG
        LOCAL s AS STRING
        LOCAL wet  AS LONG
    
       'hmm, 120 in gives me -1 for hh, 2 for mm, 0 for ss only hours is wrong
    
        wet  = ets
    
        ss   = wet MOD 60
    
        wet  = (Wet - ss) \ 60
    
        mm   = wet MOD 60    ' whole minutes
    
        hh   = wet \ 60       ' the hours portion of what's left
    
    
    
        'MSGBOX USING$ ("ets #  hh #  mm #  ss #", ets, hh, mm, ss)
    
                         ' this does not work  "0#:0#:0#" gets extra digit when ss>=10
                         ' this does not work  "##:##:##" only one zero when value < 10
        'FUNCTION = USING$("*0:*0:*0", hh,mm,ss) ' this it totally <vulgarity>  up.
        ' OK, I give up I will do a replace
    
        S = USING$("##:##:##", hh,mm,ss)
        REPLACE $SPC WITH "0" IN S
        FUNCTION = S
    
    
    END FUNCTION
    That should be enough snippets to give you some ideas...

    MCM

    Leave a comment:


  • Michael Mattias
    replied
    What are you doing? Timing the run? Setting a clock on the screen? Waiting for some particular time?

    Is this a GUI program? A console program?

    What would subjectively be the "best" way to handle your challenge depends on what you want to accomplish.

    Me, just looking at code which says "IF TIMER > MyTimeVar THEN... ", it sure looks like you are waiting for some time certain, in which case I'd certainly recommend the WaitableTimerObject approach.

    If you are timing the run from start to end, and maybe at certain points along the way, I'd just get my starting and ending (and intermediate) times into SYSTEMTIME structures (GetLocalTime()) and do the math when required.

    Leave a comment:


  • Heinz Grandjean
    replied
    Thank You

    Hello Community!
    After studying carefully all Your solutions the real way for me
    seems the WIN-API's GetSystemTimeAsFileTime().
    But if I understood correctly, the disadvantage may be, that I have to change the myUDT.myTimeVar that normally contains the individual time-values into a QUAD-type.
    Therefore I decided to use GetTickCount which is - as far as I am right (?)-
    the smaller brother of GetSystemTimeAsFileTime().
    The application normally runs only some hours (maybe over midnight) and will never overrun the 49.7 days of GetTickCount.

    Again thank You for help (I have learned much),
    greetings from Germany,
    Heinz Grandjean

    Leave a comment:


  • Barry Erick
    replied
    I usually just check for the time and if within the timer length, I make that the delay by waiting for midnight and skipping the timer for that one time.

    Leave a comment:


  • Pierre Bellisle
    replied
    Here is another variant.
    You won't have to care about those
    "jumps over midnight" before year 28,880

    Code:
     
     LOCAL qUtc1 AS QUAD
     LOCAL qUtc2 AS QUAD
     GetSystemTimeAsFileTime(BYVAL VARPTR(qUtc1)) '100-nanosecond intervals since January 1, 1601
     SLEEP 1234
     GetSystemTimeAsFileTime(BYVAL VARPTR(qUtc2)) '100-nanosecond intervals since January 1, 1601
     MessageBox %HWND_DESKTOP, FORMAT$((qUtc2 - qUtc1) / 10000000, "###,###.###") & _
                               " second elapsed", "Time elapsed", 64
    Last edited by Pierre Bellisle; 5 Feb 2008, 08:05 PM.

    Leave a comment:


  • Dave Biggs
    replied
    Here's another
    Code:
    LOCAL mytimeVar AS DOUBLE
    mytimeVar = TIMER
     
    'later on:
    IF TIMER - mytimeVar < 0 THEN
      'do something after midnight
      'elapsed time = TIMER - mytimeVar + 86400
    END IF
    Last edited by Dave Biggs; 5 Feb 2008, 06:40 PM. Reason: correction

    Leave a comment:


  • Russ Srole
    replied
    Another way:

    LOCAL mytimeVar AS SINGLE, test as single
    mytimeVar = TIMER

    later on:

    test = abs(timer-mytimevar)
    IF TEST THEN
    'do something
    END IF

    Leave a comment:


  • Adam J. Drake
    replied
    If you have the latest PB Compiler (8/4), you can use this line of code to drop a FILETIME UDT into a QUAD:

    Code:
    DIM q AS QUAD
    DIM ft AS FILETIME
    q = MAK(QUAD, ft.dwLowDateTime, ft.HighDateTime)

    Leave a comment:


  • Peter Lameijn
    replied
    GetLocalTime() + SystemTimeToFileTime() gives you actual time in nS...

    Leave a comment:

Working...
X