Ok I found the solution. The idea is to install a "verify" listener which gets called whenever text is about to be added to the StyledText
. So when text is about to be added ( from the backed up dispatch queue ) the code looks for a flag to be set indicating whether or not the threads have been terminated. If the threads have been terminated then ignore the text update. This allows the control to stop being updated while allowing the event queue to be drained. The following code snippet solves the problem.
txtOutput
is the StyledText
control.
endingThreads
is a boolean
set to true
when the threads have been terminated.
This appears to be the easiest way to handle the issue in an SWT application.
txtOutput.addVerifyListener(new VerifyListener() {
public void verifyText(VerifyEvent e)
{
if( !endingThreads )
{
e.doit = true;
}
else
{
e.doit = false;
}
}
});