SetTimer ?

In my VC6 MFC app, I establish a timer by using a call to SetTimer(...) for 
an elapsed time of 5 second intervals.  All working fine in this manner, 
but...

I need to reset this timer to start counting at zero if a certain unrelated 
event occurs.  Can this be done in this rather primitive arrangement?  I'm 
wondering if I could call KillTimer and immediately call SetTimer each time 
I need to reset this timer?  Is there a better way?  Essentially, I am 
recognizing when a mouse cursor enters a window and at that moment, I need 
to set the timer to trigger a message 5 seconds later.

Any suggestions appreciated.

Jack


0
jack6159 (6)
7/11/2006 2:01:49 AM
vc.mfc 33608 articles. 0 followers. Follow

7 Replies
1673 Views

Similar Articles

[PageSpeed] 16

Timers are a limited system resource. For this task, I would definitely kill 
the timer whenever the mouse leaves your window. Just start the timer 
whenever it enters.

-- 
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"Microsoft" <jack@dxbase.com> wrote in message 
news:uXZv03IpGHA.2444@TK2MSFTNGP03.phx.gbl...
> In my VC6 MFC app, I establish a timer by using a call to SetTimer(...) 
> for an elapsed time of 5 second intervals.  All working fine in this 
> manner, but...
>
> I need to reset this timer to start counting at zero if a certain 
> unrelated event occurs.  Can this be done in this rather primitive 
> arrangement?  I'm wondering if I could call KillTimer and immediately call 
> SetTimer each time I need to reset this timer?  Is there a better way? 
> Essentially, I am recognizing when a mouse cursor enters a window and at 
> that moment, I need to set the timer to trigger a message 5 seconds later.
>
> Any suggestions appreciated.
>
> Jack
>
> 


0
jwood (1292)
7/11/2006 2:10:07 AM
"Jonathan Wood" <jwood@softcircuits.com> wrote in message 
news:u2Yl28IpGHA.3324@TK2MSFTNGP05.phx.gbl...
| Timers are a limited system resource. For this task, I would definitely 
kill
| the timer whenever the mouse leaves your window. Just start the timer
| whenever it enters.
|
| -- 
| Jonathan Wood
| SoftCircuits Programming
| http://www.softcircuits.com
|
| "Microsoft" <jack@dxbase.com> wrote in message
| news:uXZv03IpGHA.2444@TK2MSFTNGP03.phx.gbl...
| > In my VC6 MFC app, I establish a timer by using a call to SetTimer(...)
| > for an elapsed time of 5 second intervals.  All working fine in this
| > manner, but...
| >
| > I need to reset this timer to start counting at zero if a certain
| > unrelated event occurs.  Can this be done in this rather primitive
| > arrangement?  I'm wondering if I could call KillTimer and immediately 
call
| > SetTimer each time I need to reset this timer?  Is there a better way?
| > Essentially, I am recognizing when a mouse cursor enters a window and at
| > that moment, I need to set the timer to trigger a message 5 seconds 
later.
| >
| > Any suggestions appreciated.
| >
| > Jack
| >
| >

Win timers also have a nasty habit of failing after awhile, and after the OS 
is resumed by a laptop from hybernation (they are not the most reliable 
resource...).  You might want to try an event which can be reset when you 
need it, and a timer thread which calls your process (with all applicable MT 
caveats of course) when the event expires.  It sounds though like you're 
trying to implement a tool tip, which is already available in MFC...?

-- Ed.

-----------------------------------------------------
hex->bin->b64
F9E7707A2AF502D0A899C6ACB43A2D35EB7E

0
Anon3258 (180)
7/11/2006 3:05:07 AM
Actually, timers were limited only in Win16.  There doesn't seem to be any specified limit
in Win32, and I've not hit one.  

If you call SetTimer on a timer that is already running, it resets the time and starts
over.
				joe

On Mon, 10 Jul 2006 20:10:07 -0600, "Jonathan Wood" <jwood@softcircuits.com> wrote:

>Timers are a limited system resource. For this task, I would definitely kill 
>the timer whenever the mouse leaves your window. Just start the timer 
>whenever it enters.
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
7/11/2006 3:53:15 AM
"Microsoft" <jack@dxbase.com> wrote in message 
news:uXZv03IpGHA.2444@TK2MSFTNGP03.phx.gbl...
> In my VC6 MFC app, I establish a timer by using a call to SetTimer(...) 
> for an elapsed time of 5 second intervals.  All working fine in this 
> manner, but...
>
> I need to reset this timer to start counting at zero if a certain 
> unrelated event occurs.  Can this be done in this rather primitive 
> arrangement?  I'm wondering if I could call KillTimer and immediately call 
> SetTimer each time I need to reset this timer?  Is there a better way? 
> Essentially, I am recognizing when a mouse cursor enters a window and at 
> that moment, I need to set the timer to trigger a message 5 seconds later.
>

No need to call KillTimer; just call SetTimer again, and it will reset to 
the specified timeout regardless of what it was when you called SetTimer.

-- David 


0
dc2983 (3206)
7/11/2006 4:06:26 AM
Just to check it out, I created a whole bunch of windows, and in each window, I did a
SetTimer.  I created 7426 windows before I ran out of memory (GetLastError = 14), and each
one had a timer.  SetTimer failed to return 0 at any point in this exercise.  This
suggests that the idea that timers are a limited resource is erroneous, and merely
leftover folklore from Win16 (where they were limited; in that system you couldn't have
more than 4 timers in Windows 3.0 and 8 timers in Windows 3.1).

I'm not sure that 7426 is a valid upper bound; I had just run a test in which I created
162,000 files, but I have discovered that my system has become quite sluggish, so the
upper bound may be inherited from my pre-trashing the kernel with massive file counts.
				joe

On Mon, 10 Jul 2006 20:10:07 -0600, "Jonathan Wood" <jwood@softcircuits.com> wrote:

>Timers are a limited system resource. For this task, I would definitely kill 
>the timer whenever the mouse leaves your window. Just start the timer 
>whenever it enters.
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
7/11/2006 6:18:47 AM
That may be that things have changed. However, something must be 
decrementing (incrementing) each and every timer. And I don't know if that's 
still done in response to the PC's clock tick interrupt. If so, I would 
still avoid unecessary timers.

Then again, maybe that is done differently these days too.

-- 
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:lbg6b2hqmd2smbee8bvdrl6ehrbo7qr9sp@4ax.com...
> Just to check it out, I created a whole bunch of windows, and in each 
> window, I did a
> SetTimer.  I created 7426 windows before I ran out of memory (GetLastError 
> = 14), and each
> one had a timer.  SetTimer failed to return 0 at any point in this 
> exercise.  This
> suggests that the idea that timers are a limited resource is erroneous, 
> and merely
> leftover folklore from Win16 (where they were limited; in that system you 
> couldn't have
> more than 4 timers in Windows 3.0 and 8 timers in Windows 3.1).
>
> I'm not sure that 7426 is a valid upper bound; I had just run a test in 
> which I created
> 162,000 files, but I have discovered that my system has become quite 
> sluggish, so the
> upper bound may be inherited from my pre-trashing the kernel with massive 
> file counts.
> joe
>
> On Mon, 10 Jul 2006 20:10:07 -0600, "Jonathan Wood" 
> <jwood@softcircuits.com> wrote:
>
>>Timers are a limited system resource. For this task, I would definitely 
>>kill
>>the timer whenever the mouse leaves your window. Just start the timer
>>whenever it enters.
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm 


0
jwood (1292)
7/11/2006 3:45:48 PM
Most operating systems don't decrement timers at all; instead, they have a queue of
"shortest-delta" queued elements, and don't do anything until a timer is feasible.  We
were doing this 30 years ago, and it would surprise me if anyone was "decrementing every
counter" today, or in fact ever did this.  Unforutnately, "Inside Windows NT" is
remarkably silent about timer implementation.
					joe

On Tue, 11 Jul 2006 09:45:48 -0600, "Jonathan Wood" <jwood@softcircuits.com> wrote:

>That may be that things have changed. However, something must be 
>decrementing (incrementing) each and every timer. And I don't know if that's 
>still done in response to the PC's clock tick interrupt. If so, I would 
>still avoid unecessary timers.
>
>Then again, maybe that is done differently these days too.
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
7/12/2006 9:07:58 PM
Reply:

Similar Artilces:

using SetTimer
I use extensively the timers in my View mfc application but I find the documentation is not absolutely clear. I use the version with 3 paramteres - the last one is NULL which indicates using the View OnTimer routine. In the documentation it says to use KillTimer with the first parameter being used in the SetTimer function and in some other palce to use it with the return value of SetTimer. Can someone clarify that plaeas? Thanks Rick. "Rick" <rick@cortex.com> wrote in message -> I use extensively the timers in my View mfc application but I find the > documenta...

SetTimer() for my MainFrame
Hi guys, I added a clock to my status bar, so in my CMainFrame I want OnTimer() to keep it updated. Where should I start the timer with SetTimer() and kill it with KillTimer() ? Probably in OnCreate() and OnDestroy(), does that sound right ? Thanks. Guess What. You should probably call SetTimer in OnCreate anywhere after you have already created the Status bar. Call KillTimer in your OnClose Method. AliR. "Robert A." <satan@invalid.org> wrote in message news:%23SfFBLKYFHA.228@TK2MSFTNGP12.phx.gbl... > Hi guys, > > I added a clock to my status bar, so in my C...

problem with SetTimer()
Hi All, I've a problem with SetTimer function. I've wrote this code: class myClass { void CALLBACK TimerProc( HWND hWnd, // handle of CWnd that called SetTimer UINT nMsg, // WM_TIMER UINT nIDEvent // timer identification DWORD dwTime // system time ){ //some code.... } myClass() { SetTimer (1, 1000, (TIMERPROC) TimerProc); } } the compiler returns a conversion error for 3th parameter of SetTimer (TimerProc) help me, what's wrong ?? System info: - Visual Studio 7.0 - Windows XP SP2 Make TimerProc() static. class myClass { static...

SetTimer problem
Hi, I have an application that requires processing at regular intervals. I have used SetTimer and cal back function to do the processing and it had been working fine (its a service and hence had to add message loop). Recently, in the processing I added one other function that uses a COM dll (a VFP dll to run VFP cmmands). With that, i see intermittent missing timer events (the processing was not done as expected and hence added a log. The log shows that the call back function is not called in between for some random intervals of time). I am not sure why this happens. What I am looking at now ...

How to use SetTimer
Hi All, How to use SetTimer without a Window Class? Please help I have the following code, but the TimerProc() will never been called. class MyClass { public: MyClass() { ::SetTimer(NULL, NULL, 1000, (TIMERPROC) TimerProc); } ..... static void CALLBACK TimerProc( HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) { // Do Something ......... } }; Rgds, Marco From the help: "When you specify a TimerProc callback function, the default window procedure calls the callback function when it processes WM_TIMER. Therefore, you need to...

SetTimer with nIDEvent = 0
The documentation states: "nIDEvent [in] Specifies a nonzero timer identifier." However I have mistakenly set nIDEvent = 0 on many occasions with no apparent ill effects. I've found several code examples online where people have done the same. Does anyone know the story with this? Doug E. Codemonger wrote: > The documentation states: "nIDEvent [in] Specifies a nonzero timer identifier." > > However I have mistakenly set nIDEvent = 0 on many occasions with no > apparent ill effects. > > I've found several code examples online where people ha...

SetTimer() question
I'm using the timer function 'SetTimer()' and 'KillTimer()' function to start and stop the animation. The problem is, the animation pauses during the call to the Sleep() function or call to a function that takes a long time to complete processing. What can I do so that the animation does not pause. Thank you Put the long process in a seperate thread. Or Pump messages in between your long process. You can also change your sleep to do something like this void CMyApp::Wait(DWORD HowLong) { MSG Msg; DWORD Start = GetTickCount(); while (Start + HowLong > GetTickC...

To get the SetTimer identity
Hi, I have a dialog on which the timer is displayed using SetTimer() which is binded to the dialog.Is there any API that identify this timer which is got set ..... So that, with that id i can call some API which makes the timer to start from that time it was already showing at..... Whatever the number you want! As long as you didn't use the same number for another timer.. It can be the memory address of the object who handle it. Every object of a collection can have its own timer.. Sometime, for a single timer, I simply use "1234" as the ID.. jmarc... "lucky" ...

settimer and realtime issue
hello all, I have application which diplays new messages every few minutes, and I noticed that on notebooks sometimes looks like timer stalls when computer is left idle for 2 or more hours. Is there some explenation of that? is this just Windows ? thanks ...

To get the SetTimer identity #2
Hi, I have a dialog on which the timer is displayed using SetTimer() which is binded to the dialog.Is there any API that identify this timer which is got set ..... So that, with that id i can call some API which makes the timer to start from that time it was already showing at..... isnt it the same id u called SetTimer with ..... "lucky" <Laxmanmaruthy@gmail.com> wrote in message news:1175778268.053331.256800@o5g2000hsb.googlegroups.com... > Hi, > > I have a dialog on which the timer is displayed using SetTimer() which > is binded to the dialog.Is there any AP...

Another SetTimer question
Why is it that the following settimer is not working? the call back function TimerProc_Wrapper is never called after 5 secs?Why? Thanks for any help rendered. I want to be able to interrupt the timedelay instead of using the sleep(5000). ------------------------------------------------------------------------------------------------------- Inside the testDoc.h class CTestDoc : public CDocument { //UINT MyThreadFunc(LPVOID lParam); static UINT_PTR m_TestTimer; static VOID CALLBACK CTestDoc::TestTimerProc( HWND hwnd, UINT uMsg, UINT idEvent, DWORD dw...

Why I couldn't SetTimer in ListView
I create new SDI project by AppWizard, at the final stage I modify the view class from CView to CListview. Everything is fine before I try to set a Timer in the ListView. I simply call CWnd::SetTimer to start a timer, then use classwizard to generate code to process WM_TIMER message Here comes the code: void CListView::OnTimer(UINT nIDEvent) { if (nIDEvent == 1) { .... } CListView::OnTimer(nIDEvent); } But the I found the message WM_TIMER is been delivered only once, then there are no more WM_TIMER after the first call to CListView::OnTimer. I am totally puzzled, could anyb...

problem with settimer
Hi i'm using Settimer in a service. I've called Set timer as UINT nid = ::SetTimer(NULL, 0,100,(TIMERPROC) MyTimerProc); where TimerProc is defined as void CALLBACK MyTimerProc( HWND hWnd, // handle of CWnd that called SetTimer UINT nMsg, // WM_TIMER UINT nIDEvent, // timer identification DWORD dwTime // system time ) { switch(nMsg) { case WM_TIMER: break; } } I dont know why but i dont get the WM_TIMER event in the callback function..i mean the function TimerProc is never called even after the time specified in SetTimer() func...

CWnd::SetTimer, limited global resource.
Prior to Visual C++ 2005, CWnd::SetTimer() included the following detail in it's documentation: "Timers are a limited global resource; therefore it is important that an application check the value returned by the SetTimer member function to verify that a timer is actually available." ...which had been around for many years. Did someone suddenly come to the realization that timers are no longer a limited global resource? Or, is this simply an oversight? -- Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote. http://www.peterRitchie.com/blog/ Microsoft MV...

SetWaitableTimer/SetTimer call back is not getting called
I have created a worker thread using CreateThread() function. I created a Timer Event using CreateWaitableTimer. I set the timer event using SetWaitableTimer and I include a call back function to be called when the timer expired. However, I do not hit the call back function. Is there any special code I need to add for this? Here is the snippet from my code. void CreateSTEventsAndThreads() { DWORD IDThread; stThreadEvents[0] = CreateEvent(NULL, FALSE, FALSE, NULL); timerEvent = CreateWaitableTimer(NULL, FALSE, "WaitableTimer"); stThreadHandle = CreateThread(NULL, 0,...

SetTimer()
I am using MFC's to develop and application that reads data from serial port every sec or 500ms Parse & update data into dialog boxes. This is what I have in mind, Let me know if this will work. I am really keeping it as simple as possible. I don't really need a high accuracy in Time.. CSerialIO::OnBnSerial() { ...... ...... //All Initializations here SetTimer(IDC_Time,500,Null) } CSerialIO::OnTimer(UINT nIDEvent) { ReadSerialport(); //All the data reading & Parsing is done in this function UpdateData(False); CDialog::OnTimer(UINT nIDEVENT) } Once I press...

OnTimer(), SetTimer() & KillTimer()
I have a view window that I want to update automaticaly every couple of seconds. I'm trying to use the timer functions but I'm getting strange behaviour and MSDN seems slightly contradictary. can anyone help My view class constructor contain m_uiTimer = 0 ; // m_uiTimer is an unsigned int member variabl My OnInitialUpdate() contain m_uiTimer = SetTimer( 1, 5000, NULL ) I have an OnTimer event handler containin TRACE ( _T("%s[%d] Development Note - Timer event occured\n"), _T(__FILE__), __LINE__ ) RefreshList() ; // rebuilds the contents of the lis MyListView::OnT...

SetTimer strange behavior
Found a weird problem today and didn't see it in the archives. I was doing a SetTimer based on an estimated time and happened to get a very big value (c7fffb50). Timer returned immediately which surprised me since that's on the order of 39 days. I got curious and did some testing. Even though nElapse is an UINT (which should handle ffffffff milliseconds) if I got much above 6fffffff it blew up. Below that it seemed to run fine (though I didn't wait around for 21 days just to check). Anybody seen this before? Any insight into what's going on down at the system level? Fr...

SetTimer -> OnTimer driving me crazy
Hi, I found numerous examples of SetTimer and OnTimer examples on the web and they all look similiar to what I have tried here, but my OnTimer function is never executed. I created a SDF Application and launched a dialog off of the menu. In the Dialog I call a SetTimer and then delcared a OnTimer function also a member of the same dialog object. I never get the TRACE statement in the OnTimer to fire and a button displays that the global_sent variable is never updated. Here's where I set the timer in the dialog's OnItit function: ---------------------------------------------...

pop up messages after every 60 seconds using SetTimer()
Laxman Hi, i am writing an dialog based application in which i should get the pop up messages after every 60 seconds showing the time ( using GetLocalTime() Function ). But i am not able to do it. I am finding difficulty in using UINT_PTR SetTimer( UINT_PTR nIDEvent, UINT nElapse, void (CALLBACK* lpfnTimer) (HWND, UINT, UINT_PTR, DWORD) ); Can you help me ................... BOOL Dlg::OnInitDialog() { ...... ...... SetTimer(1, 60*1000, NULL); } void Dlg::OnTimer(UINT nIDEvent) { SYSTEMTIME st; GetLocalTime(&st); ...

SetTimer ?
In my VC6 MFC app, I establish a timer by using a call to SetTimer(...) for an elapsed time of 5 second intervals. All working fine in this manner, but... I need to reset this timer to start counting at zero if a certain unrelated event occurs. Can this be done in this rather primitive arrangement? I'm wondering if I could call KillTimer and immediately call SetTimer each time I need to reset this timer? Is there a better way? Essentially, I am recognizing when a mouse cursor enters a window and at that moment, I need to set the timer to trigger a message 5 seconds later. Any...

SetTimer IDs and return values
I have an app that uses a lot of timers. I'm using enums for the IDs so that I can spot them more easily. My question is, can the return value of SetTimer be different than the ID I set it too or is it only so when SetTimer fails? IOW, can I safely count on my enum IDs to be valid nIDEvents? Thank you all and happy holidays. >I have an app that uses a lot of timers. I'm using enums for the IDs >so that I can spot them more easily. My question is, can the return >value of SetTimer be different than the ID I set it too or is it only >so when SetTimer fails? IOW, can I safel...

SetTimer / static pointer
Hi All, Two questions.. one about SetTimer and the other one about a static pointer.... I have a problem w/ the CWnd::SetTimer function. Maybe someone can give me an insight. This question regards a Windows CE [3.0] device: Let's say I have a timer running in my main dialog window started by "SetTimer(ID, .. etc)" .. then, I display modally a new window on top of the main one. In this one, I start a new timer by the same function "SetTimer(ID, ...") where the ID of this timer in this newly displayed window is different than the ID from the main window (even though th...

timer functions-SetTimer(help-urgently)
hello, I am reading a file in chunks of 512 bytes(i am reading 2 such blocks).I am calling SetTimer function.And in corresponding OnTimer function I am writing code for displaying the file data on a graph control placed in my dialog box.I am calling the KillTimer function after the 2 chunks of data are displayed as graphs. But when i close the dialog or press OK/Cancel button the dialog MFC application error box appears which asks "whether to send the error report to microsoft".Why is this coming?First i thought maybe the KillTimer function isnt properly called but th...

SetTimer (VC++ 6.0)
Hallo! In MSDN Library CWnd::SetTimer() help, we can read "Timers are a limited global resource". What mean exactly this ? How many system timers are available ? Thanks ! - Daniele - Hi Daniele, We can have as many as Timers as we want(Just define UNIQUE IDs). "Timers are a limited global resource" means that it is not affected by other processes going in the applications. >-----Original Message----- >Hallo! > >In MSDN Library CWnd::SetTimer() help, we can read "Timers are a limited >global resource". >What mean exactly this ? How many...