5

Why does this simple expression freezes Mathematica? (version 10.3.0, Windows 7 64)

SetOptions[EvaluationNotebook[], 
 NotebookDynamicExpression :> (Dynamic[
    Refresh[If[! NumericQ[myColorID], myColorID = 1]; 
     myColorID = If[myColorID == 2, 1, 2], UpdateInterval -> 0.5], 
    TrackedSymbols -> {}])]

And yet, when I do just the Dynamic part, it works fine:

Dynamic[Refresh[If[! NumericQ[myColorID], myColorID = 1]; 
  myColorID = If[myColorID == 2, 1, 2], UpdateInterval -> 0.5], 
 TrackedSymbols -> {}]

(and the same problem exists when using SetOptions[$FrontEndSession, FrontEndDynamicExpression :>... )

Kuba
  • 136,707
  • 13
  • 279
  • 740
P. Fonseca
  • 6,665
  • 2
  • 28
  • 60

1 Answers1

4

I don't know why it doesn't work, but you can skip Dynamic and put TrackedSymbols to Refresh. With this setup it won't make any troubles.

SetOptions[
 EvaluationNotebook[], 
 NotebookDynamicExpression :> Refresh[
  If[! NumericQ[myColorID], myColorID = 1]; 
  myColorID = If[myColorID == 2, 1, 2], 
  UpdateInterval -> 0.5, 
  TrackedSymbols -> {}
 ]
]

Notebook|FE|Cell DynamicExpressions are by default wrapped/treated as Dynamic by FrontEnd, this is why we could do this.

Here's an answer where I;ve shown that Dynamic/Refresh behaviour in those options is slightly different: What is the point of Refresh?

Kuba
  • 136,707
  • 13
  • 279
  • 740