Sudeep
Sudeep

Reputation: 173

Display.getDefault.syncExec() not running correctly in headless mode

I'm running my application in headless mode and for some execution i need to display a dialog in between for some specified time.

Code Sample

Display.getDefault().syncExec(new Runnable() {
@Override
    public void run() {
       //Jface Dialog code
       RuntimePauseDialog dlg = new RuntimePauseDialog();
       dialogResult = dlg.open();
    }
});

The above code will be called multiple times and for the first time the Dialog appears. From 2nd time onwards the dialog doesn't show up. Moreover run() will not be executed at all and freezes. Inside syncExec() there is a Runnable lock which gets initialized and calls wait(), which waits forever (Application freezes) I think this has something to do with Threads.

Note : The same code displays the dialog (multiple times) correctly when run from UI mode. The problem is only in headless mode.

Tried this suggestion from Stackoverflow, but since i'm running in headless mode, there will be no Workbench created and cannot use that.

Upvotes: 0

Views: 651

Answers (1)

greg-449
greg-449

Reputation: 111216

syncExec (and asyncExec) relies on there being a main Display.readAndDispatch loop running in the UI thread. In headless mode this is not the case so this is simply not going to work at all.

Upvotes: 3

Related Questions