GUIKit Example: ThreadedStopCounter
Example
This example demonstrates how you can use the InvokeThread option of user interface functions to allow user interface updates to be visible when performing a long Wolfram Language calculation by threading the calculation and ensuring that user interface update requests occur on the event dispatching thread.
Additionally, once a process is threaded, it allows the user to abort a long Wolfram Language calculation from the same user interface. This is accomplished by triggering an abort using BindEvent["action",InvokeMethod[{"ScriptEvaluator","abort"}], which does not require a kernel script evaluation to interrupt an existing kernel evaluation.
Another important feature of properly interrupting a calculation is proper placement of CheckAbort[] calls to allow interruption at certain points of the Script block, and to make sure that the rest of the Script will continue as expected. All Script blocks are automatically wrapped with AbortProtect by the GUIKit framework so that, by default, all scripts will evaluate without interruption. You should add CheckAbort blocks in scripts that perform longer calculations.