Scripting Resources for DigitalMicrograph™

banner

Dave Mitchell's DigitalMicrograph™ Scripting Website

Home | Scripts | Examples | Functions | Recent Updates | Tutorials | Resources | Publications | Consulting | Projects | Contact & Bio | Private | Search

 

Example: Thread and Dialog Interaction
Function

Example code which shows how to get a dialog to start and stop a thread, and how to have that thread communicate with the dialog - to source information, such as values in fields and to reset buttons, LEDs etc. In this example the dialog and thread are separate classes. In a second example, the thread is run from within the dialog class

Version
version:20130827, v1.0
Author
D. R. G. Mitchell
Acknowledgements
Pavel Potapov and Bernhard Schaffer are thanked for providing advice on use of the Script Object ID by which the thread can access the dialog and thence items within the dialog.
Comments
This script asks for a counting interval and a duration. When the Start button is pressed the thread counts out n intervals until the duration has elapsed. The time and interval information is printed in the Results window. The thread stops when either the Stop button is pressed or the duration has elapsed.
System Requirements
Should be compatible with all recent versions of DigitalMicrograph, but only tested on GMS 2.11 (XP).
Known Issues
Closing the dialog normally makes the dialog object go out of scope. However, since the thread has the dialog object the dialog does not go out of scope until the thread has finished and goes out of scope itself. This means that even with trapping it is not possible to send a stop signal to the thread by closing the dialog. When the dialog is closed the thread keeps running until it finishes. Do not use this method if your thread is infinite and is simply waiting on an external stop signal. Your thread must have a built-in stop signal, otherwise the thread will run forever after the dialog is closed.
Supported
Yes
Included Files
Main script file.
Source Code

See attached script