4

I'm doing a program in Mathematica 10 and I need to use different buttons like Button["Start", Module[{}, 'routine']]

It all works wonderfully when the routine takes very little time, but when I try to create buttons similar to that and the routine requires several minutes to be completed, then I click the button just after two, three seconds, the process stops.

Why? How can I fix this?

Sektor
  • 3,320
  • 7
  • 27
  • 36
user32490
  • 41
  • 1
  • Hi, welcome to Mathematica.SE, please consider taking the tour so you learn the basics of the site. Once you gain enough reputation by making good questions you will be able to vote up and down both questions and answers. When you see good ones, please vote them up by clicking the grey triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. As you receive help, try to give it too, by answering questions in your area of expertise. – rhermans Aug 19 '15 at 15:28
  • 1
    I have reformatted your question trying to improve its readability. You can always add more details, highlight a specific behaviour you are expecting and so on. – Sektor Aug 19 '15 at 15:37
  • 4
    The default evaluation method is "Preemptive". Try Method->"Queued". – Karsten7 Aug 19 '15 at 15:37

1 Answers1

3

In the documentation of Button, under Options -> Method, it says:

By default, button functions are evaluated on a preemptive link and time out after 5 seconds:

DynamicModule[{a = "start"}, {Button["does time out", Pause[6]; a = "end"], Dynamic[a]}]

Use Method->"Queued" to evaluate button functions on the main link, which never times out:

DynamicModule[{a = "start"}, {Button["does not time out", Pause[6]; a = "end", Method -> "Queued"], Dynamic[a]}]
Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263