Two handlers sharing time

Geoff Canyon gcanyon at inspiredlogic.com
Tue Dec 18 20:14:01 EST 2001


At 3:19 PM -0500 12/18/01, Shari wrote:
>Is it possible to have handlers share time?  So that when it is idle, the second handler runs?
>
>I have a very lengthy handler, that does certain things, calls other handlers, and they in turn call other handlers.  This sets up the data for the user.
>
>As it takes more than a few seconds, I've created things for the user to "do" while waiting.

One way to accomplish something like this is to break the setup task into individual steps (the smaller the better) and then do something like:

global gSetupDone

on setup
  put false into gSetupDone
  doSetupStep 1
end setup

on doSetupStep pWhichStep
  switch pWhichStep
  case 1
    blah blah
    break
  case 2
    blah blah
    break
  ...
  case 32 -- last step
    put true into gSetupDone
  end switch
  if not gSetupDone then 
    send ("doSetupStep" && (pWhichStep + 1)) to me in 1 millisecond
  end if
end doSetupStep

What this will do is process your setup just about as fast as if it were all done at once, but automatically put the process on hold for anything the user does. Note that you can't break a task up any way you like -- each time through the doSetupStep is a different execution, so local variables are lost, loops or branches that go across the separate cases would fail, etc.

You should try to break the setup task into steps that will take no more than .1 seconds each on a medium-speed computer. That way the user will never feel that the system is unresponsive.

regards,

Geoff




More information about the metacard mailing list