Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

##What is going on

By default the Dynamic, EventHandlers and various controllers like Button and Slider use a PreemptiveLink to communicate with the kernel.

Synchronous versus Asynchronous Dynamic Evaluations about the PreemptiveLink:

[...] There is no queue; instead, the front end sends one evaluation at a time and waits for the result before continuing with its other work, [...] the front end is completely locked up, and no typing or other actions are possible. [...] (* so Dynamics' updates aswell *)

In your case display = "Correct"; Pause[1]; display = rand is that "one evaluation" during which the front end is locked up. Therefore there is no reaction for display's change.

##Solutions

  • The shortest one would be to use a MainLink (Asynchronous/Queued).

Unfortunately for Notebook/Cell/FrontEndEventActions we do not have Method->"Queued" like in Button or ActionMenu.

You can check that this indeed works:

     Dynamic[x]
         (*check with and without that method*)
     Button["test", x = 1; Pause[1]; x = 2, Method -> "Queued" ]
  • FinishDynamic[]

We can use FinishDynamic[] to tell the front end that it should (blindly) update all out of date Dynamics.

This works well:

    display = "Correct"; FinishDynamic[]; Pause[1];  display = rand

The Kernel waits till the front end confirms FinishDynamic[] end, and then proceeds with Pause. Quite often it is convenient, however, one should keep in mind that this function is going to prompt all dynamics checks.

related: How to catch the “Preemptive” evaluations from within the main loop?How to catch the “Preemptive” evaluations from within the main loop?

  • ScheduledTasks

Scheduling a procedure is done immediately so it doesn't block the link anymore.

Pause[1]; expr; can be translated to RunScheduledTasks[expr, {1}]

Nesting and synchronizing multiple tasks may be tricky but here it works as intended.

This automatically gives us:

    display = "Correct"; RunScheduledTask[display = rand, {1}]

###Further readings

Evaluation order of Button[]'s actionEvaluation order of Button[]'s action

Working with ScheduledTasks inside DynamicModulesWorking with ScheduledTasks inside DynamicModules

Button with progress barButton with progress bar

##What is going on

By default the Dynamic, EventHandlers and various controllers like Button and Slider use a PreemptiveLink to communicate with the kernel.

Synchronous versus Asynchronous Dynamic Evaluations about the PreemptiveLink:

[...] There is no queue; instead, the front end sends one evaluation at a time and waits for the result before continuing with its other work, [...] the front end is completely locked up, and no typing or other actions are possible. [...] (* so Dynamics' updates aswell *)

In your case display = "Correct"; Pause[1]; display = rand is that "one evaluation" during which the front end is locked up. Therefore there is no reaction for display's change.

##Solutions

  • The shortest one would be to use a MainLink (Asynchronous/Queued).

Unfortunately for Notebook/Cell/FrontEndEventActions we do not have Method->"Queued" like in Button or ActionMenu.

You can check that this indeed works:

     Dynamic[x]
         (*check with and without that method*)
     Button["test", x = 1; Pause[1]; x = 2, Method -> "Queued" ]
  • FinishDynamic[]

We can use FinishDynamic[] to tell the front end that it should (blindly) update all out of date Dynamics.

This works well:

    display = "Correct"; FinishDynamic[]; Pause[1];  display = rand

The Kernel waits till the front end confirms FinishDynamic[] end, and then proceeds with Pause. Quite often it is convenient, however, one should keep in mind that this function is going to prompt all dynamics checks.

related: How to catch the “Preemptive” evaluations from within the main loop?

  • ScheduledTasks

Scheduling a procedure is done immediately so it doesn't block the link anymore.

Pause[1]; expr; can be translated to RunScheduledTasks[expr, {1}]

Nesting and synchronizing multiple tasks may be tricky but here it works as intended.

This automatically gives us:

    display = "Correct"; RunScheduledTask[display = rand, {1}]

###Further readings

Evaluation order of Button[]'s action

Working with ScheduledTasks inside DynamicModules

Button with progress bar

##What is going on

By default the Dynamic, EventHandlers and various controllers like Button and Slider use a PreemptiveLink to communicate with the kernel.

Synchronous versus Asynchronous Dynamic Evaluations about the PreemptiveLink:

[...] There is no queue; instead, the front end sends one evaluation at a time and waits for the result before continuing with its other work, [...] the front end is completely locked up, and no typing or other actions are possible. [...] (* so Dynamics' updates aswell *)

In your case display = "Correct"; Pause[1]; display = rand is that "one evaluation" during which the front end is locked up. Therefore there is no reaction for display's change.

##Solutions

  • The shortest one would be to use a MainLink (Asynchronous/Queued).

Unfortunately for Notebook/Cell/FrontEndEventActions we do not have Method->"Queued" like in Button or ActionMenu.

You can check that this indeed works:

     Dynamic[x]
         (*check with and without that method*)
     Button["test", x = 1; Pause[1]; x = 2, Method -> "Queued" ]
  • FinishDynamic[]

We can use FinishDynamic[] to tell the front end that it should (blindly) update all out of date Dynamics.

This works well:

    display = "Correct"; FinishDynamic[]; Pause[1];  display = rand

The Kernel waits till the front end confirms FinishDynamic[] end, and then proceeds with Pause. Quite often it is convenient, however, one should keep in mind that this function is going to prompt all dynamics checks.

related: How to catch the “Preemptive” evaluations from within the main loop?

  • ScheduledTasks

Scheduling a procedure is done immediately so it doesn't block the link anymore.

Pause[1]; expr; can be translated to RunScheduledTasks[expr, {1}]

Nesting and synchronizing multiple tasks may be tricky but here it works as intended.

This automatically gives us:

    display = "Correct"; RunScheduledTask[display = rand, {1}]

###Further readings

Evaluation order of Button[]'s action

Working with ScheduledTasks inside DynamicModules

Button with progress bar

deleted 14 characters in body
Source Link
Kuba
  • 137.7k
  • 13
  • 289
  • 751

##What is going on

By default the Dynamic, EventHandlers and various controllers like Button and Slider use a PreemptiveLink to communicate with the kernel.

Synchronous versus Asynchronous Dynamic Evaluations about the PreemptiveLink:

[...] There is no queue; instead, the front end sends one evaluation at a time and waits for the result before continuing with its other work, [...] the front end is completely locked up, and no typing or other actions are possible. [...] (* so Dynamics' updates aswell *)

In your case display = "Correct"; Pause[1]; display = rand is that "one evaluation" during which the front end is locked up. Therefore there is no reaction for display's change.

##Solutions

  • The shortest one would be to use a MainLink (Asynchronous/Queued).

Unfortunately for Notebook/Cell/FrontEndEventActions can'twe do that. It is supported with Button'snot have Method->"Queued" orlike in SynchronousUpdatingButton foror DynamicsActionMenu.

You can check that this indeed works:

     Dynamic[x]
         (*check with and without that method*)
     Button["test", x = 1; Pause[1]; x = 2, Method -> "Queued" ]
  • FinishDynamic[]

We can use FinishDynamic[] to tell the front end that it should (blindly) update all out of date Dynamics.

This works well:

    display = "Correct"; FinishDynamic[]; Pause[1];  display = rand

The Kernel waits till the front end confirms FinishDynamic[] end, and then proceeds with Pause. Quite often it is convenient, however, one should keep in mind that this function is going to prompt all dynamics checks.

related: How to catch the “Preemptive” evaluations from within the main loop?

  • ScheduledTasks

Scheduling a procedure is done immediately so it doesn't block the link anymore.

Pause[1]; expr; can be translated to RunScheduledTasks[expr, {1}]

Nesting and synchronizing multiple tasks may be tricky but here it works as intended.

This automatically gives us:

    display = "Correct"; RunScheduledTask[display = rand, {1}]

###Further readings

Evaluation order of Button[]'s action

Working with ScheduledTasks inside DynamicModules

Button with progress bar

##What is going on

By default the Dynamic, EventHandlers and various controllers like Button and Slider use a PreemptiveLink to communicate with the kernel.

Synchronous versus Asynchronous Dynamic Evaluations about the PreemptiveLink:

[...] There is no queue; instead, the front end sends one evaluation at a time and waits for the result before continuing with its other work, [...] the front end is completely locked up, and no typing or other actions are possible. [...] (* so Dynamics' updates aswell *)

In your case display = "Correct"; Pause[1]; display = rand is that "one evaluation" during which the front end is locked up. Therefore there is no reaction for display's change.

##Solutions

  • The shortest one would be to use a MainLink.

Unfortunately Notebook/Cell/FrontEndEventActions can't do that. It is supported with Button's Method->"Queued" or SynchronousUpdating for Dynamics.

You can check that this indeed works:

     Dynamic[x]
         (*check with and without that method*)
     Button["test", x = 1; Pause[1]; x = 2, Method -> "Queued" ]
  • FinishDynamic[]

We can use FinishDynamic[] to tell the front end that it should (blindly) update all out of date Dynamics.

This works well:

    display = "Correct"; FinishDynamic[]; Pause[1];  display = rand

The Kernel waits till the front end confirms FinishDynamic[] end, and then proceeds with Pause. Quite often it is convenient, however, one should keep in mind that this function is going to prompt all dynamics checks.

related: How to catch the “Preemptive” evaluations from within the main loop?

  • ScheduledTasks

Scheduling a procedure is done immediately so it doesn't block the link anymore.

Pause[1]; expr; can be translated to RunScheduledTasks[expr, {1}]

Nesting and synchronizing multiple tasks may be tricky but here it works as intended.

This automatically gives us:

    display = "Correct"; RunScheduledTask[display = rand, {1}]

###Further readings

Evaluation order of Button[]'s action

Working with ScheduledTasks inside DynamicModules

Button with progress bar

##What is going on

By default the Dynamic, EventHandlers and various controllers like Button and Slider use a PreemptiveLink to communicate with the kernel.

Synchronous versus Asynchronous Dynamic Evaluations about the PreemptiveLink:

[...] There is no queue; instead, the front end sends one evaluation at a time and waits for the result before continuing with its other work, [...] the front end is completely locked up, and no typing or other actions are possible. [...] (* so Dynamics' updates aswell *)

In your case display = "Correct"; Pause[1]; display = rand is that "one evaluation" during which the front end is locked up. Therefore there is no reaction for display's change.

##Solutions

  • The shortest one would be to use a MainLink (Asynchronous/Queued).

Unfortunately for Notebook/Cell/FrontEndEventActions we do not have Method->"Queued" like in Button or ActionMenu.

You can check that this indeed works:

     Dynamic[x]
         (*check with and without that method*)
     Button["test", x = 1; Pause[1]; x = 2, Method -> "Queued" ]
  • FinishDynamic[]

We can use FinishDynamic[] to tell the front end that it should (blindly) update all out of date Dynamics.

This works well:

    display = "Correct"; FinishDynamic[]; Pause[1];  display = rand

The Kernel waits till the front end confirms FinishDynamic[] end, and then proceeds with Pause. Quite often it is convenient, however, one should keep in mind that this function is going to prompt all dynamics checks.

related: How to catch the “Preemptive” evaluations from within the main loop?

  • ScheduledTasks

Scheduling a procedure is done immediately so it doesn't block the link anymore.

Pause[1]; expr; can be translated to RunScheduledTasks[expr, {1}]

Nesting and synchronizing multiple tasks may be tricky but here it works as intended.

This automatically gives us:

    display = "Correct"; RunScheduledTask[display = rand, {1}]

###Further readings

Evaluation order of Button[]'s action

Working with ScheduledTasks inside DynamicModules

Button with progress bar

added 82 characters in body
Source Link
Kuba
  • 137.7k
  • 13
  • 289
  • 751

##What is going on

By default the Dynamic, EventHandlers and various controllers like Button and Slider use a PreemptiveLink to communicate with the kernel.

Synchronous versus Asynchronous Dynamic Evaluations about the PreemptiveLink:

[...] There is no queue; instead, the front end sends one evaluation at a time and waits for the result before continuing with its other work, [...] the front end is completely locked up, and no typing or other actions are possible. [...] (* so Dynamics' updates aswell *)

In your case display = "Correct"; Pause[1]; display = rand is that "one evaluation" during which the front end is locked up. Therefore there is no reaction for display's change.

##Solutions

  • The shortest one would be to use a MainLink.

Unfortunately Notebook/Cell/FrontEndEventActions can't do that. It is supported with Button's Method->"Queued" or SynchronousUpdating for Dynamics.

You can check that this indeed works:

     Dynamic[x]
         (*check with and without that method*)
     Button["test", x = 1; Pause[1]; x = 2, Method -> "Queued" ]
  • FinishDynamic[]

We can use FinishDynamic[] to tell the front end that it should (blindly) update all out of date Dynamics.

This works well:

    display = "Correct"; FinishDynamic[]; Pause[1];  display = rand

The Kernel waits till the front end confirms FinishDynamic[] end, and then proceeds with Pause. Quite often it is convenient, however, one should keep in mind that this function is going to prompt all dynamics checks.

related: How to catch the “Preemptive” evaluations from within the main loop?

  • ScheduledTasks

Scheduling a procedure is done immediately so it doesn't block the link anymore.

Pause[1]; expr; can be translated to RunScheduledTasks[expr, {1}]

Nesting and synchronizing multiple tasks may be tricky but here it works as intended.

This automatically gives us:

    display = "Correct"; RunScheduledTask[display = rand, {1}]

###Further readings

Evaluation order of Button[]'s action

Working with ScheduledTasks inside DynamicModules

Button with progress bar

##What is going on

By default the Dynamic, EventHandlers and various controllers like Button and Slider use a PreemptiveLink to communicate with the kernel.

Synchronous versus Asynchronous Dynamic Evaluations about the PreemptiveLink:

[...] There is no queue; instead, the front end sends one evaluation at a time and waits for the result before continuing with its other work, [...] the front end is completely locked up, and no typing or other actions are possible. [...] (* so Dynamics' updates aswell *)

In your case display = "Correct"; Pause[1]; display = rand is that "one evaluation" during which the front end is locked up. Therefore there is no reaction for display's change.

##Solutions

  • The shortest one would be to use a MainLink.

Unfortunately Notebook/Cell/FrontEndEventActions can't do that. It is supported with Button's Method->"Queued" or SynchronousUpdating for Dynamics.

You can check that this indeed works:

     Dynamic[x]
         (*check with and without that method*)
     Button["test", x = 1; Pause[1]; x = 2, Method -> "Queued" ]
  • FinishDynamic[]

We can use FinishDynamic[] to tell the front end that it should (blindly) update all out of date Dynamics.

This works well:

    display = "Correct"; FinishDynamic[]; Pause[1];  display = rand

The Kernel waits till the front end confirms FinishDynamic[] end, and then proceeds with Pause. Quite often it is convenient, however, one should keep in mind that this function is going to prompt all dynamics checks.

related: How to catch the “Preemptive” evaluations from within the main loop?

  • ScheduledTasks

Scheduling a procedure is done immediately so it doesn't block the link anymore.

Pause[1]; expr; can be translated to RunScheduledTasks[expr, {1}]

Nesting and synchronizing multiple tasks may be tricky but here it works as intended.

This automatically gives us:

    display = "Correct"; RunScheduledTask[display = rand, {1}]

###Further readings

Evaluation order of Button[]'s action

Working with ScheduledTasks inside DynamicModules

##What is going on

By default the Dynamic, EventHandlers and various controllers like Button and Slider use a PreemptiveLink to communicate with the kernel.

Synchronous versus Asynchronous Dynamic Evaluations about the PreemptiveLink:

[...] There is no queue; instead, the front end sends one evaluation at a time and waits for the result before continuing with its other work, [...] the front end is completely locked up, and no typing or other actions are possible. [...] (* so Dynamics' updates aswell *)

In your case display = "Correct"; Pause[1]; display = rand is that "one evaluation" during which the front end is locked up. Therefore there is no reaction for display's change.

##Solutions

  • The shortest one would be to use a MainLink.

Unfortunately Notebook/Cell/FrontEndEventActions can't do that. It is supported with Button's Method->"Queued" or SynchronousUpdating for Dynamics.

You can check that this indeed works:

     Dynamic[x]
         (*check with and without that method*)
     Button["test", x = 1; Pause[1]; x = 2, Method -> "Queued" ]
  • FinishDynamic[]

We can use FinishDynamic[] to tell the front end that it should (blindly) update all out of date Dynamics.

This works well:

    display = "Correct"; FinishDynamic[]; Pause[1];  display = rand

The Kernel waits till the front end confirms FinishDynamic[] end, and then proceeds with Pause. Quite often it is convenient, however, one should keep in mind that this function is going to prompt all dynamics checks.

related: How to catch the “Preemptive” evaluations from within the main loop?

  • ScheduledTasks

Scheduling a procedure is done immediately so it doesn't block the link anymore.

Pause[1]; expr; can be translated to RunScheduledTasks[expr, {1}]

Nesting and synchronizing multiple tasks may be tricky but here it works as intended.

This automatically gives us:

    display = "Correct"; RunScheduledTask[display = rand, {1}]

###Further readings

Evaluation order of Button[]'s action

Working with ScheduledTasks inside DynamicModules

Button with progress bar

added 1658 characters in body
Source Link
Kuba
  • 137.7k
  • 13
  • 289
  • 751
Loading
added 682 characters in body
Source Link
Kuba
  • 137.7k
  • 13
  • 289
  • 751
Loading
Source Link
Kuba
  • 137.7k
  • 13
  • 289
  • 751
Loading