Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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:

Clear[res]
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

Clear[res]
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

share|improve this question
add comment

1 Answer 1

up vote 8 down vote accepted

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.

share|improve this answer
1  
You can also directly change the DynamicEvaluationTimeout option value, but that is not recommended - forums.wolfram.com/mathgroup/archive/2010/Apr/msg00490.html –  Chris Degnen Jul 2 '12 at 13:45
    
Thanks! That was exactly what I wanted. –  gogoolplex Jul 2 '12 at 13:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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