Application.DoEvents Method

Yields time back to REALbasic in tight loops. Calling DoEvents inside a loop allows REALbasic to maintain the interface for the user while continuing to execute the loop.

Syntax

Application.DoEvents [milliseconds]


Parameters

milliseconds (Optional)

Integer


However, using DoEvents from a multithreaded application is not supported and will likely cause instability. You should consider using threads to handle lengthy operations rather than placing them in the main thread and calling DoEvents to maintain the interface.

If the current method is running inside a Thread, DoEvents will yield to the main thread instead of running one iteration of the event loop inside the thread, causing confusion.

If you use DoEvents inside a loop, the you cannot use the UserCancelled function to detect whether the user pressed the Esc key (Windows or Linux) or Command-period (on Macintosh) to break out of the loop. Since DoEvents keeps the user interface responsive while the loop is running, you can add a button to the user interface that the user can click to stop the loop.

The optional parameter specifies the amount of time you want the currently executing thread to sleep. DoEvents can cause a Thread to sleep with a resolution greater than 16 milliseconds. If all threads are sleeping, then REALbasic yields back time to the system. This allows you to write applications that don't use up to 100% of the CPU during tight loops.

Specifying zero milliseconds causes the next waiting thread to execute. A negative value specifies no sleep. The default is -1.