Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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. >>

share|improve this question
    
As the answers given below point out, V10.3 is simply being smarter than V9. So it's not a bug, but an improvement. – m_goldberg Jan 6 at 5:44

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.

share|improve this answer

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.

share|improve this answer

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.