Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

problem with settimer

69 views
Skip to first unread message

Usman Jamil

unread,
Jul 16, 2003, 9:49:38 AM7/16/03
to
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() function..Is the problem with my CallBack function
or what. coz it seems to be working well in other applications..that are not
services.

Thanx and regards

Usman Jamil


Peter M.

unread,
Jul 16, 2003, 12:15:16 PM7/16/03
to
Why don't you use plain call, like this:
SetTimer( hwnd, // handle to main window
IDT_TIMER, // timer identifier
n, // n-second interval
(TIMERPROC) NULL); // no timer callback

and handle WM_TIMER notification? Is there any special reason for you to
define your own timer procedure? If I'm wrong, correct me please.
Regards,
Peter


"Usman Jamil" <us...@advcomm.net> wrote in message
news:uQPRwD6S...@TK2MSFTNGP11.phx.gbl...

Joseph M. Newcomer

unread,
Jul 16, 2003, 12:02:03 PM7/16/03
to
First: the nMsg parameter is useless, and there is never a reason to ever look at it. It
will ALWAYS be WM_TIMER. The HWND is meaningless, it will always be NULL. The nIDEvent is
rarely useful, since it is rare to have two different timers calling the same timer proc
(if you need two timers, use two timer procs). Only the dwTime has a slight possibility of
being useful.

You will only get timer callbacks if your message pump is active, so if you are off doing
some long computation, no timer events will be seen.
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Bob Moore

unread,
Jul 16, 2003, 6:08:55 PM7/16/03
to
On Wed, 16 Jul 2003 18:49:38 +0500, Usman Jamil wrote:

>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() function..Is the problem with my CallBack function
>or what. coz it seems to be working well in other applications..that are not
>services.

If you don't have a message pump (which seems likely in a service),
then your callback won't be called. The "callback" for a timer is
actually called from within message processing in your thread, not by
Windows itself.

You might be better off looking at multimedia timers - see the docs
for timeSetEvent. These support "true" callbacks.

--
Bob Moore [WinSDK MVP]
http://www.mooremvp.freeserve.co.uk/
(this is a non-commercial site and does not accept advertising)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Do not reply via email unless specifically requested to do so.
Unsolicited email is NOT welcome and will go unanswered.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Usman Jamil

unread,
Jul 18, 2003, 2:15:35 AM7/18/03
to
Hi
Thanx for the tip. I used timeSetEvent for it and its working now..but there
is another problem now..The scenario is that the service opens multiple
threads and i have to invoke a seperate timer for each thread..now after
some timer perhaps when many threads have been opened and i try to stop the
service it wont stop..rather hang..can u please tell me if there is some
problem in using multiple mutimedia timers..or is there any check i must
make using mutimedia timer to avoid such situations..

thanx and regards

Usman Jamil
"Bob Moore" <bo...@mvps.org> wrote in message
news:n1jbhv8sabc2hongt...@4ax.com...

Bob Moore

unread,
Jul 18, 2003, 8:03:08 AM7/18/03
to
On Fri, 18 Jul 2003 11:15:35 +0500, "Usman Jamil" <us...@advcomm.net>
wrote:

>can u please tell me if there is some


>problem in using multiple mutimedia timers..or is there any check i must
>make using mutimedia timer to avoid such situations..

I am not aware of any such problem relating to multimedia timers.
Provided that your threads call timeKillEvent before their run
function exits there shouldn't be any issue. Possibly the problem lies
in your threading architecture - was there a problem before you
started using multimedia timers, or did you never get as far as
testing shutdown ?

0 new messages