-
Timer issue
Okay I need to figure out a way to setup a timer that will up variables every second. Now I know there is a windows function that I could use (through the windows procedure functions) that will send a message of my choosing on the ineterval of my choice. Now I can't remember the function off hand, but I could find that out on my own. However, I've read that if the system is slowed down and these calls stack up then only one call would actually get through to the windows procedure function. Is there a way to setup such a timer to do a similar job (on multiple windows in an MDI interface) that would actually do the job on each interval without the possibility of loosing some of these messages (if the system slows down)?
Thanks
-
Use SetTimer() for the WinProc method you described. I don't think you will actually "loose" timer events (unless the message Q overflows). However, if you have a timer setup for every second, and the message loop thread gets tied up doing some work, then the timer events can get backed up and come in one after another (ie. not 1 second apart).
Any other approach is going to involve creating another thread. It can be as simple as calling Sleep(1000) in a loop, or you could use a waitable timer.
What do you need to do every second? Using SetTimer() may be sufficient for your purposes as long as the period between each WM_TIMER message doesn't need to be exactly 1 second.
gg
-
Yeah I guess the SetTimer() function would work (just read up on it in the MSDN), although I was thinking of another function that you could specify which windows message to pass on (thus you could setup your own windows message and pass that on after the elapsed time ended).
In the one I was thinking of stated that if I passed on a message in short loops (say trying to keep track of time as it elapsed... which this would be a poor method for that anyways), the messages would instead of stacking in the queue would be destroyed if one in the queue already existed.
What I'm doing is keeping track of idle time on a connection (and disconnecting the connection if the idle time reached the max). Thus every second I need the idle variable for that connection needs to be upped by 1. (And if they stack then once the system comes back up to speed the idle time would be adjusted as appropriate. However, possibly giving the user a slightly higher idle time then usually allowed, but I can live with that... if the system slows down.)
Thanks for your help
-
Yep, this is common task. Have you considered keeping a "timestamp" of the last time there was activitey on the connection.
Since detecting an expired idle connection isn't really a time critical task (I'm assuming) then you could setup a timer for 10 or 15 seconds (or whatever granularity you like) to check the deltas of the current time and the last activity "timestamp" on your connections.
I usually use a DWORD for this, coupled with GetTickCount() (don't forget to account for wrap-around of the DWORD.)
gg
-
Okay I have it all working, now I have one question which MSDN doesn't answer about the SetTimer() function. Does this function only wait until the timer has elapsed once (or the time-out value ends once) or does it continue to do the same thing every second until you call KillTimer()? Just wondering if I have to recall the SetTimer function everytime the elapsed time ends.
-
-