Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!sdd.hp.com!ucsd!ucbvax!ALEX.CSS.GOV!lynnes From: lynnes@ALEX.CSS.GOV (Christopher Lynnes) Newsgroups: comp.windows.x.motif Subject: Re: Timer Interrupt Message-ID: <9101241425.AA23877@alex.CSS.GOV> Date: 24 Jan 91 14:25:00 GMT Sender: daemon@ucbvax.BERKELEY.EDU Distribution: inet Organization: The Internet Lines: 50 > I am trying to make a main event handler which will run for at least >the given time, and returns the control back to the program. >That is, it should be a temparary XtAppMainLoop. > > I made up the following function: > >void TempEventH(XtAppContext app, unsigned int time) >{ > XEvent event; > > XtAppAddTimeOut(app, time, NULL, NULL); /* put up a timer event */ > while(!(XtAppPending(app) & XtIMTimer)){ /* until it arrives */ > XtAppNextEvent(app, &event); /* do the event processing */ > XtDispatchEvent(&event); > } >} > > Of course, it does not work. But, I don't know why. >Any suggestions? Many thanks in advance. My guess is that XtAppPending() returns the input mask for all of the events in the queue which INCLUDES the timer that you add before the loop. The result is that the routine returns immediately. (Is this so?) Instead, try using XtAppPeekEvent, which returns True if the next event in the queue is a window event, and False if it's a timer or input event. What's more, if it is a timer, it will dispatch the event automatically, so you should be able to use >void TempEventH(XtAppContext app, unsigned int time) >{ > XEvent event; > > XtAppAddTimeOut(app, time, NULL, NULL); /* put up a timer event */ while (XtAppPeekEvent(app, &event)) /* Peeking leaves event on queue */ { XtAppNextEvent(app, &event); /* This gets the event from the queue */ XtDispatchEvent(&event); } } I tried this (without application contexts) and it seems to work. Chris Lynnes ===== : = ::::: Teledyne Geotech ===== :: == ::::: Alexandria, Virginia ::: === (703) 739-7316 :: == lynnes@seismo.CSS.GOV : =