User Tools

Site Tools


put_your_program_to_sleep.htm
Navigation:  How To's and Troubleshooting > How to… >====== Put Your Program To Sleep ====== Previous pageReturn to chapter overviewNext page

NewC7.jpg

There are some occasions when you may want to introduce a timed delay to your Windows applications. You don't want to use a LOOP structure to simulate a delay because the LOOP command is processor dependent. Looping 1000 times on one machine may be quite different from another in regards to length of time or duration.

Instead, use the Windows Sleep API function, which releases the CPU and lets other apps in the system effectively multitask. The Sleep function suspends the execution of the current thread for a specified interval.

To add the SLEEP prototype to your application, include the following MODULE structure inside the Global Map of your program or application:

  MODULE('')

   SLEEP(LONG),PASCAL

  END

The SLEEP API has a time parameter, in milliseconds, for which to suspend execution. A value of zero causes the thread to relinquish the remainder of its time slice to any other thread of equal priority that is ready to run. If there are no other threads of equal priority ready to run, the function returns immediately, and the thread continues execution.

   SLEEP(1000)  !delay for 1 second

Besides using SLEEP() to introduce a delay, at times it is also useful to allow other programs to “catch up” with your applications, and SLEEP() can be useful for this. For example, consider the following sample code:

SETCURSOR(Cursor:Wait)

System{Prop:DDETimeout} = 12000

WordChannel = DDEClient('WinWord','System')

IF NOT WordChannel

   RUN('C:\Program Files\Microsoft Office\Office\WinWord.exe',0)

   SLEEP(50) !Introduce a little delay to allow MSWord to initialize.

END

 

WordChannel = DDEClient('WinWord','System')

DDEExecute(WordChannel,'[Insert “My text” + CHR$(10)]')

DDEClose(WordChannel)

SetCursor(Cursor:Arrow)

On slower machines, it is possible that the MSWord program may not finish its initialization sequence on start up before the DDEClient command is executed. SLEEP() allows the MSWord program to finish its startup and open a proper DDE channel to the Clarion program.

put_your_program_to_sleep.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1