Application.DoEvents Method

Yields time back to REALbasic in loops. Intended for console applications in which there is no main event loop.

Syntax
Application.DoEvents [milliseconds]

Parameters
milliseconds | Integer (Optional)

# Notes

You can call DoEvents in the Run event in a console application to create your own main event loop.

However, using DoEvents in a GUI application will likely cause instability. In effect, you would be placing a main event loop inside the 'real' main event loop. 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.