I want to monitor a long calculation that is triggered by the release of a Slider. While one can indicate running calculations when the main evaluation loop is controlled by a queued Button, the same cannot be done with more direct Dynamic approaches. A bit of trial and error actually confirms that only Button and not any of the other controls (Slider, Locator, even EventHandler) can be evaluated non-preemptively.

This works as expected, displaying a ProgressIndicator while the long calculation is performing:

long[] := Module[{a = .3}, Do[a = 3.5 a (1 - a), {i, n}]];
{active, x} = {False, 1};
{Slider[Dynamic@x, {0, 1}], 
 Button["Update", (active = True; long[]; active = False;), Method -> "Queued"]}
Dynamic@{If[active, ProgressIndicator[i, {0, 10^6}], "..."], active}

Mathematica graphics

The same cannot be done using a Slider. The update command was put in the second argument of Dynamic, more precisely in the slot which is evaluated when the controller is released. As you can see, it still evaluates long (the string is printed) but it does not switch active and consequently it does not display the ProgressIndicator.

long[] := Module[{a = .3}, Do[a = 3.5 a (1 - a), {i, 10^6}]];
{active, x} = {False, 1};
Slider[Dynamic[x, {(x = #) &, (active = True; Print["evaluating..."]; long[]; 
     active = False) &}], {0, 1}]
Dynamic@{If[active, ProgressIndicator[i, {0, 10^6}], "..."], active}

Mathematica graphics

No amount of TrackedSymbols :> {...}, ContinuousEvaluation -> False or SynchronousUpdating -> False helped.

Is there any way to force $f_{end}$ in Dynamic[$x$, {$f$, $f_{end}$}] to be evaluated in a queued fashion, not preempting (its own) previous commands?

As a sidenote: It would be interesting to look into the implementation of Button as it definitely stands on something different than EventHandler. Does anyone has some insight on this matter?

  • $\begingroup$ Are you aware of this? It looks to me like an authoritative "not possible" (yet?) to what you want to achieve, or am I missunderstanding your question? $\endgroup$ Mar 28, 2013 at 21:36
  • $\begingroup$ @Albert Thanks! I did perform a search but missed that one. Seems to be relevant and thus the answer to my question is no. $\endgroup$ Mar 28, 2013 at 22:03
  • $\begingroup$ would you consider this question to be a duplicate to be removed? $\endgroup$ Mar 28, 2013 at 22:10
  • $\begingroup$ @Albert Yes, I guess it is. I was thinking overnight whether there is any subtle difference offering an escape, but no, there is no solution to this issue yet. Would be nice to know more about why the Method option was not implemented for dynamic controllers other than Button. $\endgroup$ Mar 29, 2013 at 7:57
  • $\begingroup$ @rm -rf I'm not sure I did the appropriate thing here: should I simply delete my Q or is it fine to be closed as duplicate? In the latter case, should I refer to this from the master Q (in a comment) as it elaborates on the same matter and might be useful for others? $\endgroup$ Mar 29, 2013 at 8:01


Browse other questions tagged or ask your own question.