Previous Book Contents Book Index Next

Inside Macintosh: AppleScript Language Guide / Part 2 - AppleScript Language Reference
Chapter 8 - Handlers / Command Handlers for Script Applications
Handlers for Stay-Open Script Applications

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 repeat
If while this script application is running it receives a Close command, the property p is reset to 0 and the script application begins incrementing p all
over again:

tell application "Increment" to close
AppleScript can't deal with such interruptions automatically.

Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996