How to quit app?

If i try to run this code in another app:

tell application "myapp" to quit

then i get this error:

error “myapp got an error: AppleEvent timed out.” number -1712

myapp:

on run
end run

on app_code()
	--here is my app	
end app_code

on idle
	app_code()
	do shell script "sleep 300"
end idle

on quit
	continue quit
end quit
on run
end run

on app_code()
	--here is my app	
end app_code

on idle
	app_code()
	return 300
end idle

– NG
http://macscripter.net/viewtopic.php?pid=156274#p156274

Unless there is something else you need to do in this handler, it is useless…

on quit
   continue quit
end quit

If you need an idle handler, maybe have experienced users, that know how to force quit, and something to clean up before you quit, then you need something like this: MacScripter / properties reset

[applescriptglobal shouldQuit
global didCleanup
on run
set shouldQuit to false
set didCleanup to false
try
– lengthy operation goes here
repeat with x from 1 to 10
if shouldQuit then error
say (x as string)
delay 5
end repeat
on error
tell me to quit
end try
end run
on quit
if not didCleanup then
– cleanup operation goes here
say “cleaning up”
set didCleanup to true
end if
set shouldQuit to true
continue quit
end quit