|
-
Nov 7th, 2008, 09:43 AM
#1
Thread Starter
New Member
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
-
Nov 7th, 2008, 02:19 PM
#2
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.
-
Nov 9th, 2008, 09:00 AM
#3
Thread Starter
New Member
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.
-
Nov 9th, 2008, 09:04 AM
#4
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.
-
Nov 9th, 2008, 09:23 AM
#5
Thread Starter
New Member
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 ..
-
Nov 9th, 2008, 09:40 AM
#6
Re: SystemTimer - SetTimer fails
 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.
 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.
-
Nov 9th, 2008, 09:58 AM
#7
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.
-
Nov 12th, 2008, 02:51 PM
#8
Thread Starter
New Member
Re: SystemTimer - SetTimer fails
I verified SetTimer returns a non-Zero value and it is set properly.
Let's try other alternatives.
-
Nov 12th, 2008, 03:04 PM
#9
Thread Starter
New Member
Re: SystemTimer - SetTimer fails
 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.
-
Nov 12th, 2008, 03:52 PM
#10
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|