0
$\begingroup$

Possible Duplicate:
Why do buttons with ChoiceDialog freeze the front end?
Why is SystemDialogInput failing to return a save file path?
Evaluation inside Button stops after some seconds

I am trying to use the code from:

Make a button that evaluates a function over and over

to make a button evaluate some code and plot the results, but when the code takes more than a few seconds it does not plot the results.

Here is a simple example that illustrates the problem I am having

For short time periods it works fine:

 func := (Pause[1]; Plot[Sin[x], {x, 0, 5}]); DynamicModule[{result = Null}, Column[{Button["Press", result = func], Dynamic[result]}]] 

But if I change the pause to be 10 seconds it doesn't show the plot

 func := (Pause[10]; Plot[Sin[x], {x, 0, 5}]); DynamicModule[{result = Null}, Column[{Button["Press", result = func], Dynamic[result]}]] 
$\endgroup$
0

1 Answer 1

2
$\begingroup$

Try

func := (Pause[10]; Plot[Sin[x], {x, 0, 5}]); DynamicModule[{result = Null}, Column[{Button["Press", result = func, Method -> "Queued"], Dynamic[result]}]] 

From MMA documentation:

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

Use Method->"Queued" to evaluate button functions, which never times out.

$\endgroup$
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.