home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / mac / programm / 18705 < prev    next >
Encoding:
Text File  |  1992-11-20  |  2.3 KB  |  55 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!nih-csl.dcrt.nih.gov!FAXCSL!FIXER
  3. From: fixer@faxcsl.dcrt.nih.gov (Chris Spiral Catfish Tate)
  4. Subject: Re: best way to pause in app ?
  5. Message-ID: <1992Nov20.135348.1785@alw.nih.gov>
  6. Sender: postman@alw.nih.gov (AMDS Postmaster)
  7. Reply-To: fixer@faxcsl.dcrt.nih.gov
  8. Organization: Computer Systems Laboratory, DCRT, NIH
  9. References: <brownlow.722219238@stmartin>
  10. Date: Fri, 20 Nov 1992 13:53:48 GMT
  11. Lines: 42
  12.  
  13. In article <brownlow.722219238@stmartin>, brownlow@informix.com (Keith Brownlow) writes:
  14. >Is there a toolbox command to make the application wait x number of seconds
  15. >before continuing processing ?  I've tried looping for 1000's of seconds but
  16. >without doing anything in the loop, it's more or less instantly coming back.
  17.  
  18. Several things you can use (code given in C):
  19.  
  20. 1)  You could use Delay(60L * num_of_seconds, &dummy_long);
  21.  
  22.     This is okay, except that it pretty much freezes the machine until the
  23.     delay is over, i.e. no background processing.
  24.  
  25. 2)  You could call WaitNextEvent(0, &dummy_event, 60L * num_of_seconds, 0L);
  26.  
  27.     This would give time to other processes, but would not necessarily give
  28.     them the full time you specify.  If you're the only process running, for
  29.     example, you would return immediately.
  30.  
  31. 3)  Combination approach:
  32.  
  33.     long timeNow;
  34.  
  35.     timeNow = TickCount();
  36.     while (TickCount() - timeNow < 60L * num_of_seconds)
  37.     {
  38.         (void) WaitNextEvent(0, &dummyEvent, 0L, 0L);
  39.     }
  40.  
  41.     This repeatedly gives time to other processes until the specified amount
  42.     of time has elapsed, at which point you drop out of the while loop.
  43.  
  44. Calling Delay() for long periods of time (i.e. seconds) is pretty anti-
  45. social to other processes; I'd probably use approach 3) if I were going to
  46. be pausing for more than about a second.  The one caveat is that you *might*
  47. not get control back for a much longer time, if another process is trying to
  48. hog the machine by not calling WaitNextEvent().
  49.  
  50. ------------------------------------------------------------------------------
  51. Christopher Tate             | The Leadfoot Collection, Continued:
  52. Management System Designers  |     * Heavy Fuel (Dire Straits)
  53.                              |     * Last Scene in September (Preston Reed)
  54. fixer@faxcsl.dcrt.nih.gov    | Because driving fast is a cathartic experience.
  55.