Consider the following module:

startBrowser[] := Module[{},
   $browserstatus = True;
   ReinstallJava[CommandLine -> DIRJAVA, ClassPath -> DIRBOTA];
   BROWSER = JavaNew["org.nilostep.botautil.BrowserFacade"];


stopBrowser[] := Module[{},
   $browserstatus = False;
   BROWSER = Null;


 If[$browserstatus, color1 = Green, color1 = Red, color1 = Gray];
   {"Browser ", Graphics[{color1, Disk[]}, ImageSize -> 20]},
   {"Hive ", Graphics[{color2, Disk[]}, ImageSize -> 20]
 Button["Start Browser", startBrowser[];],
 Button["Stop Browser", stopBrowser[];],
 ControlPlacement -> Bottom,
 Initialization :> {color1 = Gray, color2 = Gray}

Now, consider the following scenario:


the manipulate panel becomes, as expected, visual. Without clicking the buttons the browser is started and stopped as follows:


as a result the image in the panel changes from red to green and a Java- and browser instance can be seen in the Task Manager.


as a result the image in the panel changes from green to red, the browser instance is killed after which the Java session is terminated.

Now, my question.

I expected that the same would happen when I click the buttons in the Manipulate program.

But when I click on the "Start Browser" button, a message appears with the text "One or more dynamic objects are taking excessively long, etc...". When I click "Continue Waiting" the button turns green and the Browser can be seen in Task Manager.

Then when I click the "Stop Browser" button, Java is uninstalled, but executing the quitDriver[] method on the BROWSER object failed.

I don't quite understand this behavior. How can I execute the start- and stop modules by buttons on the Manipulate panel?

Why do modules work when executed from a cell but have side effects when run from a button click action on a manipulate panel?

  • $\begingroup$ Do you think it is a valid duplicate: 19556? Or 120397 $\endgroup$
    – Kuba
    Mar 14 '17 at 16:40
  • $\begingroup$ I wouldn't have found it by the description although the explanation of both questions is the same. You look different at it when you already understand the difference between preemptive and queued. $\endgroup$ Mar 14 '17 at 16:54
  • 1
    $\begingroup$ Once the duplicate is marked it says "this question already has an answer in..." which makes more sense in this context. $\endgroup$
    – Kuba
    Mar 14 '17 at 16:56