Possible help for extra-time-consuming operations?
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
case DerStatus = "off"
put false into KeepMeAlive
exit to top
if KeepMeAlive = true then send "TickleMe" to me in NumSecs seconds
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:
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.
Re: Possible help for extra-time-consuming operations?
On 4/15/2016 8:25 PM, Quentin Long wrote:
> 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
> case DerStatus = "off"
> put false into KeepMeAlive
> exit to top
> end case
> end LifeLine
> on TickleMe
> if KeepMeAlive = true then send "TickleMe" to me in NumSecs seconds
> end TickleMe
How great to see you on the list! Been a while.
I'm afraid the technique won't work though. The first "tickleMe" will
trigger when the local is set to "on" but after that a long handler
won't return control to the queue until it finishes, so any pending
"tickleMe" messages won't execute until the long handler is finished.
The fix is to wait 0 with messages inside the long handler, which yields
time to the engine and allows LC to do housekeeping. That works best
inside a repeat loop, otherwise it gets iffy.