[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [platform-swt-dev] MessageBox blocks display thread on linux
|
I tested with Eclipse 3.1.2 and 3.2 with exactly the same behaviour. So its
hard to believe, this simple and basic behaviour is a bug on both major
releases !?
I will send a bug report in parallel.
Here the code to reproduce:
---- snipped ---
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
/*
* This test class open a shell with a button and a label
* The label is refreshed by a Thread each second and shows a counter
incrementing
* A click on the button will open a MessageBox, waiting for a user input.
* While waiting for the user input the refresh of the label using
asyncExec() is blocked on Linux/GTK.
* Closing the MessageBox will de-block the thread and the refresh events
are processed.
*
* On Windows the behavior is different/better. The refresh of the label is
done also while wating for the
* user input of the MessageBox.open() call.
*
*/
public class TestSnipped {
static int ourCnt = 1;
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
final Label time = new Label(shell, SWT.BORDER);
time.setText("" + ourCnt);
time.pack();
Button dialog = new Button(shell, SWT.PUSH);
dialog.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent arg0) {}
public void widgetSelected(SelectionEvent arg0) {
MessageBox mb = new MessageBox(new Shell(display), SWT.OK|
SWT.CANCEL|SWT.SYSTEM_MODAL);
mb.open();
}
});
dialog.setText("Start Messagebox");
shell.pack();
shell.setSize(200, 200);
shell.open();
new Thread() {
public void run() {
while (true) {
try {
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
display.asyncExec(new Runnable() {
public void run() {
ourCnt++;
time.setText("" + ourCnt);
}
});
}
}
}.start();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}