Results 1 to 10 of 10

Thread: SystemTimer - SetTimer fails

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    9

    SystemTimer - SetTimer fails

    Hi All,

    I have a VB code in which System Timer (see below ) is used.

    Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerProc As Long) As Long


    The program scans a table for a specific interval and once scan is complete. It sets the timer using SetTimer function. and after the specified seconds , it triggers the event again.

    The code works fine , but some times the timer is being set correctly , but after the specific time period the event is not getting triggered.

    And it looks like application hangs.

    Is there any known problem with the system timer ? If so , what's the alternative way ..

    Thanks in advance in

    JK
    Last edited by jkcool; Nov 7th, 2008 at 09:44 AM. Reason: title was incorrect

  2. #2
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: SystemTimer - SetTimer fails

    You may wish to take a look at SelfTimer class, it should make it fairly easy for you to use the system's timer and IDE won't crash in case you have to hit the Stop button.

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    9

    Re: SystemTimer - SetTimer fails

    Thank you very much .... I'll try that ...

    I just need another clarification ...

    Is there any known issue with the system timer ? I am looking for a reason for the system timer not to trigger at times.

  4. #4
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: SystemTimer - SetTimer fails

    If you display a message box under IDE, it may break the timer, because it prevents the event from being triggered. There is no problem in compiled code.

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    9

    Re: SystemTimer - SetTimer fails

    There is no message box. Usually it runs fine for few hours and then suddenly falls in to non-responding state. When logs were given , we understood that ... the timer is not triggering the event after the specific interval ..

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: SystemTimer - SetTimer fails

    Quote Originally Posted by jkcool
    There is no message box. Usually it runs fine for few hours and then suddenly falls in to non-responding state. When logs were given , we understood that ... the timer is not triggering the event after the specific interval ..
    Well, SetTimer timers don't stop unless they are terminated. There are 3 ways to terminate a timer
    1. Use KillTimer
    2. Set same timer to an interval of zero (doesn't kill the timer, just stops it)
    3. If the timer was assigned to an hWnd, when the hWnd closes, timer is destroyed automatically.

    So, if one of the 3 above aren't in play, then something else is going on and it isn't with the timer. You must understand timers too. Read the documentation on Timers. Timers work by having the system post a message to the app's message queue. Posted messages (i.e., PostMessage API) always take lower priority than Sent messages (i.e., SendMessage API). Therefore a timer is not guaranteed to always fire on the specific interval, it can be off by several ms.

    Quote Originally Posted by MSDN
    http://msdn.microsoft.com/en-us/library/ms644927(VS.85).aspx
    The WM_PAINT message, the WM_TIMER message, and the WM_QUIT message, however, are kept in the queue and are forwarded to the window procedure only when the queue contains no other messages.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: SystemTimer - SetTimer fails

    Here is another scenario, don't know if it applies to your code.
    Are you just creating new timers every time? If so, are you using KillTimer on the old timer or just setting its interval to zero. There is a max timer count, can't recall what it is at the moment. I would also recommend checking the return value of SetTimer. If it returns zero, then SetTimer actually failed.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #8

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    9

    Re: SystemTimer - SetTimer fails

    I verified SetTimer returns a non-Zero value and it is set properly.

    Let's try other alternatives.

  9. #9

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    9

    Re: SystemTimer - SetTimer fails

    Quote Originally Posted by LaVolpe
    Timers work by having the system post a message to the app's message queue. Posted messages (i.e., PostMessage API) always take lower priority than Sent messages (i.e., SendMessage API). Therefore a timer is not guaranteed to always fire on the specific interval, it can be off by several m
    So is there any possibility of message being lost when System tries to send to App's queue.

  10. #10
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: SystemTimer - SetTimer fails

    Wouldn't think so, but if your code is using PeekMessage or GetMessage and not processing the WM_Timer then that could possibly happen. Also if your code is using an message loop created by API, and not calling DispatchMessage then message won't be sent to the timer procedure.

    Are you using any subclassing, other than to retrieve the timer messages? Are you using a message loop? Maybe show us your timerproc routine?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width