kipnis@janus.Berkeley.EDU (Gary Kipnis) (01/12/90)
Hi, a while back someone suggested using the following method to implement
a timer in windows:
void FAR PASCAL Sleep(hWnd, wMilliSeconds)
HWND hWnd;
WORD wMilliSeconds;
{
MSG Msg;
SetTimer(hWnd, TIMER_ID, wMilliSeconds, NULL);
GetMessage(&Msg, hWnd, WM_TIMER, WM_TIMER);
KillTimer(hWnd, TIMER_ID);
return;
}
For some reason after making a call to this function several time the
system hangs. If I eliminate this function from the code then everything
works fine (without a delay though).
Does anyone have any ideas what might be wrong with the above method or
suggest a different approach.
Thank you,
gary
papa@pollux.usc.edu (Marco Papa) (01/12/90)
In article <33605@ucbvax.BERKELEY.EDU> kipnis@janus.Berkeley.EDU (Gary Kipnis) writes: |Hi, a while back someone suggested using the following method to implement |a timer in windows: | |void FAR PASCAL Sleep(hWnd, wMilliSeconds) |HWND hWnd; |WORD wMilliSeconds; |{ | MSG Msg; | | SetTimer(hWnd, TIMER_ID, wMilliSeconds, NULL); | GetMessage(&Msg, hWnd, WM_TIMER, WM_TIMER); | KillTimer(hWnd, TIMER_ID); | return; |} | |For some reason after making a call to this function several time the |system hangs. If I eliminate this function from the code then everything |works fine (without a delay though). | |Does anyone have any ideas what might be wrong with the above method or |suggest a different approach. I was the one that originally posted the query. You're right the sample code above crashes the system ALL THE TIME. I ended up doing it as I said in one of my follow-ups. Do a SetTimer that instead of NULL has a pointer to a real routine. This routine sets a flag when it is invoked at the timeout. The main "sleep" routine goes into a PeekMessage loop to let everybody else in, until the flag is changed. Then sleep exits. Works just fine. No crashes. -- Marco -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= "Xerox sues somebody for copying?" -- David Letterman -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=