Article # 514, added by Geoworks, historical record
| first |
previous |
index |
next |
last |
Misusing threads to do more than one task.
Q. I need to open a dialog containing a text window and a Cancel button to show progress messages and handle user cancellation of an operation. The operation is a single method which also initializes the dialog. It sends status text strings to be displayed in the text window and checks if Cancel has been pressed. To do that, it calls two application messages periodically. However, the dialog does not show up until the operation method, the one that initializes it, returns. Is there any way to force the dialog update without its preliminary opening (it works fine if I open it before the user selected to connect)? While the operation method is working, mouse events are not processed, so I can not click on the Cancel button. How do I yield the control to the UI to handle the mouse within this slow operation? A. I believe you can't really easily accomplish what you want in a single method. In fact, what you really want is two different threads working, which implies two different objects in charge. The first thread (probably your process thread) should be doing the connection work and sending notification messages to the progress dialog box. The second thread (probably your UI thread) should run the dialog box and send a cancellation message to the first thread when the Cancel button is hit. The SDK documentation has a section in the GenInteraction chapter of the Objects book that deals with progress interactions. Check out the on-line documentation. The ASCII file you want to look in is on the disc: \TECHDOCS\ASCII\OBJECTS\OGENINT.TXT. Look for section 7.3.2.4, called "Progress Interactions."