[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.tools] problem stopping a SWT thread when I close the shell
|
Dear eclipe users,
Could you help me on the specific issue I have with my piece of code ?
Basically my program is doing a nice animation using a thread in a very
simple canvas. The redraw of the canvas is made every 20ms, and I have
3 buttons: start/pause/stop to control the animation. All the buttons are
doing what they are for.
If I am doing the following sequence : start/stop, close the window
(using the X icon on the top-right of the window), the program is
stopping correctly with no issue.
but if I want to close the shell without clicking stop button, I have the
following error message
org.eclipse.swt.SWTException: Widget is disposed
at org.eclipse.swt.SWT.error(SWT.java:2332)
at org.eclipse.swt.SWT.error(SWT.java:2262)
at org.eclipse.swt.widgets.Widget.error(Widget.java:385)
at org.eclipse.swt.widgets.Control.getDisplay(Control.java:735)
at org.eclipse.swt.widgets.Widget.isValidThread(Widget.java:593)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:315)
at org.eclipse.swt.widgets.Control.redraw(Control.java:1349)
at Interface$2.run(Interface.java:85)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at
org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:98)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:1815)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1549)
at org.eclipse.swt.widgets.Display.release(Display.java:1598)
at org.eclipse.swt.graphics.Device.dispose(Device.java:212)
at Interface.main(Interface.java:136)
Exception in thread "main"
What is very strange is that I copy EXACTLY the same piece of code
to stop the thread in the stop button listener and inside the shell
dispose listener ????
shell.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
String thdname=thd.getName();
thd=null;
disposeColors();
}
});
public void widgetSelected(SelectionEvent event) {
String thdname=thd.getName();
thd=null;
canvas.redraw();
}
};
Could you help me on that ?
Thank you in advance.