Different Approaches to Multithreaded User Interface Programming

You can take three general approaches to the use of multiple threads in conjunction with the User Interface Library.

The first approach is to perform all of your user interface processing in the main thread. You create panels and call functions like SetCtrlAttribute and SetCtrlVal in the main thread. You use your other threads for I/O processing or data analysis. For example you could acquire data continuously in a separate thread. If you wanted to display the data in the main thread, you could place the acquired data in a global variable and use state variables to indicate how much data was available for display. To learn how to define global variables so that they are thread safe, refer to the help for the Thread Safe Variable class of functions.

Another example of the first approach is to create a new thread each time the user clicks on a command button on your user interface panel. Each thread performs the assigned task and then terminates. Because a separate thread performs the user-requested task, the user can continue to operate the user interface panel without waiting for the task to complete.

In the second approach, you create all of your panels in the main thread but call functions such as SetCtrlAttribute and SetCtrlVal from different threads. For instance, if you are performing data acquisition in a separate thread, you could update a numeric control with a newly acquired data point by calling SetCtrlVal from the data acquisition thread.

In the third approach, you create panels in multiple threads. The set of panels in each thread behave almost as if they were in separate processes. For instance, each set of panels is in a separate z-plane grouping. The panels in the thread of the active panel are on top of the panels in the other threads. Also, pop-up panels are modal only with respect to panels of the same thread. If you use InstallPopup to display a dialog box, the end-user cannot access any other panels in the same thread, but is free to operate panels you create in different threads. You can display a separate task bar button for each thread.

Lifetime of Child Threads

Panels and Multithreading

Event Processing and Multithreading

Posting Events and Multithreading

Standard I/O Window and Multithreading

Simulating Events and Multithreading

Cursors and Multithreading

Sleep Policy and Multithreading

Font Pop-Up Defaults and Multithreading

Batch Drawing and Multithreading

File Dialogs and Multithreading

Current Working Directory and Multithreading

Thread Blocking

Windows Messages and Multithreading

Printing and Multithreading

System Attributes and Multithreading

Timer Controls and Multithreading