after idle

Difference between version 3 and 4 - Previous - Next
'''`[after]` idle``` schedules a script for evaluation at moment when the
interpreter is idle.


** Synopsis **

    :   '''[after] idle''' ''script'' ?''script script ...''?


** See Also **

   [Update considered harmful]:   Why `after idle` should be used instead of `update` or `update idletasks`.


** Description **


Concatenates the ''script'' arguments together with space separators (just as in the '''same manner as `[concat]''' command)`, and arranges for the resulting script to be evaluated latoner as an tidlme callback. Twhen script will bhe run exa[Tctly once, thve next timloop%|%e the event loop] ihas enteredo and cthivere are no events to process., The command returns an identifier that `[after can bcel]` can used to cancel the delvayed command lusing '''[after caioncel]'''. If an error occurs while executing the script then the '''[bgerror%|%background error handler]''' meis challed.


The event loop considers the system to be idle when there are no events ready
to be evaluated in the normal queue.  As long as any channel that is ready to
be repad or written and has an `[chan event]` event handler associated with it,
the system is not considered idle because the event handler is continuously
placed into the active queue until the channel is no longer ready.


----
A typical, use of this command (and perhaps the most important one) ius when youf n`afteer idle`, is to [keep a 
GUI alive during a long calculation]. This isA rofuteine docane with the [update] crformm and, bulit this slowse down yourk computation and upda
the is no good choicre because: [Update considhered harmful]. Instead uitself sfomethingr likater:

======proc dostuff {} {
    do something
    after idle [list after 0 $[namyCommespance which dostuff]]
}
======where `$myCommand` does one step of a multi-step 

<<calculation and calls the above line after having done the single step until all steps are finished. This>> will smoothly keep your GUI alive and is no performance hit like [update] or [update| idletasks].
----
**See also**
   * [after]
   * [after cancel]
   * [after info]
<<categories>> Command | Tcl syntax help