home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-11-19 | 1.6 KB | 52 lines | [TEXT/MPS ] |
- /*
- File: TTimeSchedulerExample.cp
-
- Contains: This module shows an example the TTimeScheduler class.
-
- Copyright: © 1993 by Apple Computer, Inc., all rights reserved.
-
- */
-
- #include "TInitSLM.h" // the TInitSLM class and SLM include files
- #include "TTimeSchedulerExample.h"
-
- /*————————————————————————————————————————————————————————————————————————————————————
- main
-
- This example simply schedules an operation to occur after a given time. First we
- create an instance of TTimeSheduler, Next we create an instance of the operation. Here
- the operation simply beeps twice to let us know that it has fired.
- ————————————————————————————————————————————————————————————————————————————————————*/
- main()
- {
- TInitSLM initLibraryManager; // initialize the shared library manager
-
- if( initLibraryManager.Failed() ) // If we failed, let's go home
- return 1;
-
- TAlert *thebeeper; // This operation will beep twice
- TTimeScheduler *timeScheduler;
-
- if( timeScheduler = new TTimeScheduler )
- if( thebeeper = new TAlert() ) { // create a new alert operation
- thebeeper->SetTime( 2000 ); // alert us roughly after 2 seconds
-
- TStopwatch *stopwatch = new TStopwatch; // let's see if it really fires after 2 seconds
-
- timeScheduler->Schedule( thebeeper ); // schedule the operation
-
- while (!thebeeper->GetDone()); // loop until the operation fires
-
- if (stopwatch)
- cout << "Fired after " << stopwatch->ElapsedMilliseconds()
- << " milliseconds" << endl;
-
- delete timeScheduler; // free the Scheduler
- delete thebeeper; // free the alert operation
- delete stopwatch; // free the stopwatch
- }
-
- return 0;
- }
-
-