4
$\begingroup$

I have upgraded to 10.3 from Mathematica 9.0. However, in 9.0 things that ran well will not run in 10.3.

A typical example is:

Button["Import File", Import[SystemDialogInput["FileOpen", ".txt"], "List"]]

The code above runs in 9.0, but an error is generated in 10.3. I wonder whether in 10.3 the method used has changed which causes Mathematica to emit the error.

The error message is:

SystemDialogInput::nprmtv: SystemDialogInput is not currently supported within preemptive evaluations. >>

$\endgroup$
  • $\begingroup$ As the answers given below point out, V10.3 is simply being smarter than V9. So it's not a bug, but an improvement. $\endgroup$ – m_goldberg Jan 6 '16 at 5:44
8
$\begingroup$

Add Method -> "Queued"

Button["Import File", Import[SystemDialogInput["FileOpen", ".txt"], "List"], 
 Method -> "Queued"]

From IntroductionToControlObjects

So if you have an evaluation that you expect will take more than a couple of seconds to evaluate, you should use Method->"Queued". Clicking such a button will use the main link when evaluating its function, and that evaluation will be queued along with evaluations queued using Shift+Enter.

| improve this answer | |
$\endgroup$
7
$\begingroup$

The code above 9.0 is good

Unfortunately, this is not true. Even in version 9 this code was not good, but it just did not warn you about it. Take this simpler example, that only prints the file-name of the selected file and try it in version 9:

Button["Import File", Print[SystemDialogInput["FileOpen"]]]

If you try the button and select a file quickly, then it will print the file-name. If you need more than some seconds to select the file, it doesn't print the file-name. The reason is that preemtive evaluations have a timeout to not block the user interface.

Therefore, if you have a button with an action that takes longer, you need to use the option

Method->"Queued"

even in version 9. In version 10.3, Mathematica just doesn't allows for this error and warns you.

| improve this answer | |
$\endgroup$

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.