Re: Timer event
- To: mathgroup at smc.vnet.net
- Subject: [mg104207] Re: [mg104205] Timer event
- From: Leonid Shifrin <lshifr at gmail.com>
- Date: Sat, 24 Oct 2009 02:36:29 -0400 (EDT)
- References: <200910230236.WAA27918@smc.vnet.net>
One possibility is to use Dynamic with an UpdateInterval option. This is a slightly modified example from Mathematica help: This models a function you want to execute (it produces a side effect - new definitions at runtime - so that you can see whether or not it was called) Clear[f]; f[x_] := f[x] = x^2; Now set the desired time in a line like this: Dynamic[Refresh[(a = DateString[{"Hour", ":", "Minute", ":", "Second"}]; If[a === "21:41:05", f /@ Range[10]; Print["Now printing the message"]]);, UpdateInterval -> 1]] At a given time, you will see the message printed (in the Messages window), and if you inspect the definitions of <f> you will see that it did execute: ?f Global`f f[1]=1 f[2]=4 f[3]=9 f[4]=16 f[5]=25 f[x_]:=f[x]=x^2 Of course, you may use any function you want in place of <f> - this is just an example. The problem is however that you will need this Dynamic statement to be on the active part of your notebook - otherwise it won't trigger due to the optimization employed in Dynamic. I don't know if it's possible to turn this optimization off. Perhaps there are other workarounds or solutions involving Dynamic. Regards, Leonid On Fri, Oct 23, 2009 at 6:36 AM, Garapata <warsaw95826 at mypacks.net> wrote: > An post in 2005/2006 asked about creating a timer or perhaps more > accurately a timer event in Mathematica. The responses recommend > using JLink and an AddPerioical routine described in the JLink > documentation in version 5.2. > > I'd like to create a timer event or perhaps a number of such timer > events such that Mathematica would run some function or take some > action at a specified time. > > Can one do this any more directly in Mathematca, without using JLink? > > Thanks > >
- References:
- Timer event
- From: Garapata <warsaw95826@mypacks.net>
- Timer event