69
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
'calculate sum of all array elements -- this will surely take time!
dim
sum, f
as
word
sum =
0
for
f =
0
to
49999
sum = sum + arr(f)
doevents
'don't want to stall other events so allow their execution
while we are crunching numbers
next
f
Multiple Doevents Calls
Let us say we are in event handler on_event_1. This event handler executes a
doevents call. The VM begins processing other events in the queue, and starts
executing an event handler on_event_3, which also contains a doevents
statement.
In this case, a new doevents round will begin. Only when it completes, control will
be returned to event handler on_event_3, which will complete, and then return
control to the previous doevents (the one from event handler on_event_1).
The point here is that control will not be returned to on_event_1 until on_event_3
fully completes execution, since on_event_3 contains a doevents statement in
itself.
Memory Allocation When Using Doevents
When a procedure utilizes doevents, it means its execution gets interrupted, while
other procedures get control. We have no way to know which other procedures will
get control, as this depends on the events which will wait in the queue.
As a result, a procedure which utilizes doevents, and any procedures calling it
(directly or through other procedures) cannot share any memory space with any
other procedure in the project. This would lead to variable corruption -- procedures
newly executed will use the shared memory and corrupt variables which are still
needed for the procedures previously interrupted by doevents.