1Tcl_DoWhenIdle(3) Tcl Library Procedures Tcl_DoWhenIdle(3)
2
3
4
5______________________________________________________________________________
6
8 Tcl_DoWhenIdle, Tcl_CancelIdleCall - invoke a procedure when there are
9 no pending events
10
12 #include <tcl.h>
13
14 Tcl_DoWhenIdle(proc, clientData)
15
16 Tcl_CancelIdleCall(proc, clientData)
17
19 Tcl_IdleProc *proc (in) Procedure to invoke.
20
21 ClientData clientData (in) Arbitrary one-word value to pass
22 to proc.
23______________________________________________________________________________
24
26 Tcl_DoWhenIdle arranges for proc to be invoked when the application be‐
27 comes idle. The application is considered to be idle when
28 Tcl_DoOneEvent has been called, could not find any events to handle,
29 and is about to go to sleep waiting for an event to occur. At this
30 point all pending Tcl_DoWhenIdle handlers are invoked. For each call
31 to Tcl_DoWhenIdle there will be a single call to proc; after proc is
32 invoked the handler is automatically removed. Tcl_DoWhenIdle is only
33 usable in programs that use Tcl_DoOneEvent to dispatch events.
34
35 Proc should have arguments and result that match the type Tcl_IdleProc:
36
37 typedef void Tcl_IdleProc(
38 ClientData clientData);
39
40 The clientData parameter to proc is a copy of the clientData argument
41 given to Tcl_DoWhenIdle. Typically, clientData points to a data struc‐
42 ture containing application-specific information about what proc should
43 do.
44
45 Tcl_CancelIdleCall may be used to cancel one or more previous calls to
46 Tcl_DoWhenIdle: if there is a Tcl_DoWhenIdle handler registered for
47 proc and clientData, then it is removed without invoking it. If there
48 is more than one handler on the idle list that refers to proc and
49 clientData, all of the handlers are removed. If no existing handlers
50 match proc and clientData then nothing happens.
51
52 Tcl_DoWhenIdle is most useful in situations where (a) a piece of work
53 will have to be done but (b) it is possible that something will happen
54 in the near future that will change what has to be done or require
55 something different to be done. Tcl_DoWhenIdle allows the actual work
56 to be deferred until all pending events have been processed. At this
57 point the exact work to be done will presumably be known and it can be
58 done exactly once.
59
60 For example, Tcl_DoWhenIdle might be used by an editor to defer display
61 updates until all pending commands have been processed. Without this
62 feature, redundant redisplays might occur in some situations, such as
63 the processing of a command file.
64
66 At present it is not safe for an idle callback to reschedule itself
67 continuously. This will interact badly with certain features of Tk
68 that attempt to wait for all idle callbacks to complete. If you would
69 like for an idle callback to reschedule itself continuously, it is bet‐
70 ter to use a timer handler with a zero timeout period.
71
73 after(n), Tcl_CreateFileHandler(3), Tcl_CreateTimerHandler(3)
74
76 callback, defer, idle callback
77
78
79
80Tcl 7.5 Tcl_DoWhenIdle(3)