Different Approaches to Multithreaded User Interface Programming
- Updated2023-02-21
- 2 minute(s) read
Different Approaches to Multithreaded User Interface Programming
You can take three general approaches to the use of multiple threadsmultiple threads in conjunction with the User Interface Library.
Perform All User Interface Processing in the Main Thread
The first approach is to perform all of your user interface processing in the main thread. Create panels and call functions like SetCtrlAttribute and SetCtrlVal in the main thread; use your other threads for I/O processing or data analysis. For example, you can acquire data continuously in a secondary thread. If you want to display the data in the main thread, you can place the acquired data in a global variable and use state variables to indicate how much data is available for display. If you use global variables, you must ensure that they are thread safe.
Another example of the first approach is to create a new thread each time the user clicks a command button on your user interface panel. Each thread performs the assigned task and then terminates. Because a secondary thread performs the user-requested task, the user can continue to operate the user interface panel without waiting for the task to complete.
Separate User Interface Processing in Multiple Threads
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 perform data acquisition in a secondary thread, you can update a numeric control with a newly acquired data point by calling SetCtrlVal from the data acquisition thread.
Create Panels Using Multiple Threads
In the third approach, you create panels in multiple threads. The set of panels in each thread behaves almost as if it were in a separate process. 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 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.