Possible help for extra-time-consuming operations?

Quentin Long cubist at aol.com
Fri Apr 15 21:25:53 EDT 2016


Have pondered the issue of ensuring that the OS does *not* label a seemingly-'frozen' LC app as unresponsive. The following code (which I haven't actually tried in LC, shame on me) might be helpful. Some notes after the code…

========================

local KeepMeAlive = false
local NumSecs = 4

on LifeLine DerStatus

case DerStatus = "on"
put true into KeepMeAlive
TickleMe
break

case DerStatus = "off"
put false into KeepMeAlive
break

default
exit to top
end case

end LifeLine

on TickleMe
if KeepMeAlive = true then send "TickleMe" to me in NumSecs seconds
end TickleMe

========================

How to use this code: Put the code into your stack script, or a backscript, or wherever, as you deem appropriate. When a handler has a time-consuming chunk of code in it, do the following:

LifeLine ("on")

-- Time-consuming
-- chunk
-- of
-- code

LifeLine ("off")

I used the case structure to provide for any future use-case in which you want more options than just "keep this thing alive" or not. NumSecs is a local variable so that it can be easily adjusted in case this code is run under an OS that thinks, say, 2 seconds is a long-enough period to justify treating an app as unresponsive.

========================

It occurs to me that if you're looking for specific strings in a Very Large File, and you're reading the VLF in N-character-long chunks, you want to be careful that you don't overlook instances of a sought-for string which have a between-chunks boundary within them.

Say you're reading 1000-character chunks, and your sought-for StringX *starts* at char 999 within the VLF. In this case, only character 1 of StringX will be found within the first chunk; only characters 2 thru -1 of StringX will be found within chunk 2. If you *just* look *within* each chunk as you read it, you won't find the instance of StringX which started at character 999.



"Bewitched" + "Charlie's Angels" - Charlie = "At Arm's Length"
Read the webcomic at [ http://www.atarmslength.net ]!
If you like "At Arm's Length", support it at [ http://www.patreon.com/DarkwingDude ].


More information about the use-livecode mailing list