UI freezes when running a long operation in a jface wizard [message #1778074] |
Sat, 09 December 2017 07:46 |
Ali Sedaghat Messages: 17 Registered: April 2015 |
Junior Member |
|
|
Hi,
I have a UI update operation that may take several seconds to complete. I've used progress monitor to prevent ui freeze as follows:
getContainer().run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor arg0) throws InvocationTargetException, InterruptedException {
arg0.beginTask("", IProgressMonitor.UNKNOWN);
//some code
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
//ui update opeation
}
});
arg0.done();
}
However, the UI still freezes while executing the ui update operation. Any advice would be appreciated.
[Updated on: Sat, 09 December 2017 08:09] Report message to a moderator
|
|
|
Re: UI freezes when running a long operation in a jface wizard [message #1778094 is a reply to message #1778074] |
Sun, 10 December 2017 03:12 |
Eclipse User |
|
|
|
Your `getContainer().run(true, ..., IRunnableWithProgress)` causes your runnable to be forked off to another thread. But your Runnable then does a `Display#asyncExec()` which causes your UI update to happen on the SWT thread. You're effectively executing your UI update operation directly.
You have two options:
1. Wrap your UI update operation with `BusyIndicator#showWhile()` to show the busy cursor: it at least indicates to the user that some long-running operation is in progress.
2. Periodically dispatch any pending SWT events during your UI update operation (e.g., by calling `Display#readAndDispatch()`). This will cause your UI to seem live.
3. Break up your UI operation into non-UI work and UI work, and run the non-UI work via `getContainer().run()`.
|
|
|
Powered by
FUDForum. Page generated in 0.01821 seconds