Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!pollux.usc.edu!papa From: papa@pollux.usc.edu (Marco Papa) Newsgroups: comp.windows.ms Subject: Re: timer for windows Message-ID: <22247@usc.edu> Date: 11 Jan 90 20:11:20 GMT References: <33605@ucbvax.BERKELEY.EDU> Sender: news@usc.edu Organization: Felsina Software, Los Angeles, CA Lines: 35 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 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=