Home > Archive > Tcl > September 2006 > Event at specific time
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Event at specific time
|
|
|
| Is there a way to make an event happen at a specific time of day, but
which is effectively
taking no cpu time.
e.g. I want to display a message at 10:30 every day to say "Eat Banana"
or whatever.
Obviously the proce would need to be running, but in the background
taking virtually nil resources.
I could format two vars as time_hour & time_min and set a trace on
time_hour which is executed at 30 min intervals, and when 10 is
detected do the same for time_min at say 30 sec intervals.
BUT, there must be a better way, surely.
Regards, Niv.
| |
| Jeff Godfrey 2006-09-22, 8:01 am |
| "Niv" <kev.parsons@mbda.co.uk> wrote in message
news:1158930416.705235.255490@h48g2000cwc.googlegroups.com...
> Is there a way to make an event happen at a specific time of day,
> but
> which is effectively
> taking no cpu time.
You can use [after] to schedule a future event. You'll just need to
figure out what the delta time value should be...
Jeff
| |
| Michael Schlenker 2006-09-22, 8:01 am |
| Niv schrieb:
> Is there a way to make an event happen at a specific time of day, but
> which is effectively
> taking no cpu time.
>
> e.g. I want to display a message at 10:30 every day to say "Eat Banana"
> or whatever.
>
> Obviously the proce would need to be running, but in the background
> taking virtually nil resources.
>
> I could format two vars as time_hour & time_min and set a trace on
> time_hour which is executed at 30 min intervals, and when 10 is
> detected do the same for time_min at say 30 sec intervals.
>
> BUT, there must be a better way, surely.
Either use [after] or if your talking about a standalone script use one
of the notification systems available for your OS (cron, or the windows
equivalent which should be manageble with TWAPI).
See the end of:
http://wiki.tcl.tk/1382
Michael
| |
| Donal K. Fellows 2006-09-22, 8:01 am |
| Niv wrote:
> I could format two vars as time_hour & time_min and set a trace on
> time_hour which is executed at 30 min intervals, and when 10 is
> detected do the same for time_min at say 30 sec intervals.
>
> BUT, there must be a better way, surely.
Ultimately, not really. But you can use a single process to handle many
different waits and using a tiny sliver of processing time every 30
seconds is not very much. Alternatively, use the OS service for doing
this sort of thing (cron on Unix, the Schedule service on Windows, both
of which may be controlled through the 'at' command). But note that the
underlying waiter still has to do pretty much what you propose anyway,
even if it is someone else's process doing it for you.
Donal.
| |
| Neil Madden 2006-09-25, 7:02 pm |
| Jeff Godfrey wrote:
> "Niv" <kev.parsons@mbda.co.uk> wrote in message
> news:1158930416.705235.255490@h48g2000cwc.googlegroups.com...
>
> You can use [after] to schedule a future event. You'll just need to
> figure out what the delta time value should be...
For which the [clock] command is sure to be useful. From the wiki
(http://wiki.tcl.tk/after):
proc at {time args} {
if {[llength $args]==1} {set args [lindex $args 0]}
set dt [expr {([clock scan $time]-[clock seconds])*1000}]
after $dt $args
} ;# RS
With usage examples:
at 9:31 puts Hello
at 9:32 {puts "Hello again!"}
In the original example, the OP wanted this to happen *every* day, so
perhaps you need to combine this with the "every" proc on the same page.
It should be quite possible to implement this command sequence:
every day at 10:30 say "Eat Banana!"
Likewise [at 10:30 every day say "Eat Banana!"] should also work. You
just need to get [every] to [clock scan] its argument, and implement
[say] to do whatever (e.g., use puts or tk_messageBox or ...).
-- Neil
|
|
|
|
|