# Why isn't Refresh working as expected? [duplicate]

This seems to me to be a very easy question, but I can't seem to figure it out. Instead of updating every 1 second, it auto-updates as quickly as possible.

Clear[t];
t = 1; Dynamic[Refresh[t++, UpdateInterval -> 1, TrackedSymbols :> {t}]]


I've checked the documentation to no avail. Could someone explain this behaviour an propose a fix?

-

## marked as duplicate by Kuba, m_goldberg, bobthechemist, Jens, Michael E2Jul 23 '14 at 3:00

From the docs: "UpdateInterval->t specifies that updating should, if possible, be done at least every t seconds." You could use a scheduled task to update a symbol, and then display the symbol with Dynamic. – mfvonh Jul 22 '14 at 15:02
@mfvonh I have edited the question to clarify my problem. – E.O. Jul 22 '14 at 15:10
closely related – Kuba Jul 22 '14 at 15:46
@Kuba That seems like a duplicate. Do you not think so? – Mr.Wizard Jul 22 '14 at 17:58
@Mr.Wizard I think so but no 100% sure. Sure enought to cast a close-vote though :) – Kuba Jul 22 '14 at 22:03

When a Symbol is "tracked" it means that when its value changes the Dynamic expression is refreshed, therefore your input updates as fast as possible because every refresh changes the value of t which causes a refresh which... you get the picture.

Compare:

Clear[t];

t = 1; Dynamic[Refresh[t++, UpdateInterval -> 1, TrackedSymbols -> {}]]

-

Refresh only sets a limit on how long expression can go without being updated. To keep t form being updated more often add a pause.

t = 1; Dynamic[Refresh[Pause[1]; t++, UpdateInterval -> 1, TrackedSymbols :> {t}]]


or do what Mr.Wizard indicated, which is better.

But this sort of thing is best done by higher level constructs such as Clock or Trigger. For example:

status[t_, t1_] := Row[{t, " > ", threshold, " is ", t > t1}]

Dynamic[With[{dt = 1, tmax = 10, threshold = 4},
t = Clock[{0, tmax, dt}, tmax, 1]; status[t, threshold]]]


The above will run for 10 seconds and will update once a second showing whether or not the value of t has passed t = 4.

Trigger gives more control. The following does what the previous example does, but allows the process to be paused and restarted further, the process can be repeated without re-evaluating the code.

With[{dt = 1, tmax = 10, threshold = 4},
Column[{
Dynamic @ status[t, threshold],
Trigger[Dynamic@t, {0, tmax, dt}, dt,
AppearanceElements -> {"PlayPauseButton", "ResetButton"}]}]]

-