Strange Message Dialog Issue [message #523157] |
Thu, 25 March 2010 11:46 |
Vijay Raj Messages: 608 Registered: July 2009 |
Senior Member |
|
|
I have a message dialog in which i ask a question and based on yes or no i do some additional work.
For some strange reason the MessageDialog.openQuestion method returned always yes without opening the actual dialog .
on analysing i found that this was related to different threads accessing and disposing shells.
I have created a snippet for the same,
Is it an issue????
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class Snippet
{
public static void main(String[] args)
{
Display display = new Display();
final Shell shell = new Shell(display);
shell.setSize(400, 300);
final Shell s = new Shell(shell);
s.setSize(100, 100);
s.open();
Thread t = new Thread(new Runnable()
{
@Override
public void run()
{
Display.getDefault().asyncExec(new Runnable()
{
@Override
public void run()
{
boolean openQuestion = MessageDialog.openQuestion(s, "", "Yes Or No");
System.out.println(openQuestion);
}
});
}
});
t.start();
Thread t1 = new Thread(new Runnable()
{
@Override
public void run()
{
Display.getDefault().asyncExec(new Runnable()
{
@Override
public void run()
{
s.dispose();
}
});
}
});
t1.start();
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
}
---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
[Updated on: Thu, 25 March 2010 11:46] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03112 seconds