I would like to trigger a long calculation inside a dynamic module with a Button. It seems that the evaluation stops without an error-message after some seconds. I made a test outside the a dynamic module:

Button["run", res = Total[Table[i; Pause[1], {i, 1, 3}]]]

After pressing the button, the result is: 3 Null

Ok but if the calculation takes 6 seconds

Button["run", res = Total[Table[i; Pause[1], {i, 1, 6}]]]

Then res is not assigned.

Why does it happen and how can it be avoided, also inside a DynamicModule. I would like something like this:

  • Button to start a simulation run

  • Another Button which does some analysis on the simulation results


This behaviour is explained in the documentation of Button under Examples > Options > Method. By default, button functions are evaluated on a preemptive link which times out after 5 seconds. To prevent the code from timing out you can set Method -> "Queued" which will run the code on the main link.

  • 1
    $\begingroup$ You can also directly change the DynamicEvaluationTimeout option value, but that is not recommended - forums.wolfram.com/mathgroup/archive/2010/Apr/msg00490.html $\endgroup$ – Chris Degnen Jul 2 '12 at 13:45
  • $\begingroup$ Thanks! That was exactly what I wanted. $\endgroup$ – gogoolplex Jul 2 '12 at 13:53
  • $\begingroup$ I'm facing the same issue with a SetterBar instead of a Button - Method option does not exist for SetterBar. $\endgroup$ – mathheadinclouds Dec 21 '18 at 12:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.