Interrupting a Script Application's Handlers
A stay-open script application handles incoming commands even if it is already running a handler in response to a previous command. This means that execution of a handler can be interrupted while another handler is run. Because script applications are not multitasking, execution of the first handler halts until the second one finishes.This can cause problems if both handlers modify the same script property or global variable or if both attempt to modify an application's data. For example, suppose that running a script application named Increment causes it to increment the property
p
for several minutes:
property p : 0 on close set temp to p set p to 0 return temp end close set p to 0 repeat 1000000 times set p to p + 1 end repeatIf while this script application is running it receives a Close command, the propertyp
is reset to 0 and the script application begins incrementingp
all
over again:
tell application "Increment" to closeAppleScript can't deal with such interruptions automatically.