Project: SWT
Bug 76823 [doc] Display.asyncExec example needs to check for isDisposed
Reported: 2004-10-22 12:12:08 | Status: resolved fixed

The example cited in the online SWT documentation should add a test: // do time-intensive computations ... // now update the UI. We don't depend on the result, // so use async. display.asyncExec (new Runnable () { public void run () { if (myWindow.isDisposed()) // check if still around return; myWindow.redraw (); } }); // now do more computations In some products, I've noticed .log files littered with exceptions because the asyncExec is processed after the window has already closed. It wouldn't be a bad idea to integrate this check into the SWT API, e.g.: myWindow.asyncUpdate(new Runnable...); This in turn would check if the widget still exists before executing the runnable.

Files changed in fix:
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java