Mirco
Mirco

Reputation: 31

Eclipse RCP: Display.getDefault().asyncExec still blocking my GUI

I have a simple viewPart offering some text fields to enter parameters for a selenium test. After filling out these fields the user may start the test which approx. needs 30-45 minutes to run. I want my GUI to be alive during this test giving users the chance to do other things. I need a progress monitor.

I tried to put the selenium test in a job containing Display.getDefault().asyncExec to run it. But my GUI freezes after some seconds giving the busyindicator. The selenium does not update any other view but the progress monitor.

Is there another way to ensure that the job wont block my GUI?

Best, Mirco

Upvotes: 2

Views: 2789

Answers (2)

Kelibiano
Kelibiano

Reputation: 81

I would suggest to split your code into code that updates the UI and the code that executes other business. Execute all of it in a separate thread, and when you need to retrieve or set some action to the UI then use the "Display.getDefault().asyncExec".

Thread thread = new Thread("Testing") {

    // some shared members

    public void run() {

        someBusiness();

        // or use syncExec if you need your thread
        // to wait for the action to finish
        Display.getDefault().asyncExec(new Runnable() {

            @Override
            public void run() {
                // UI stuff here
                // data retrieval
                // values setting
                // actions trigging 
                // but no business
            }

        });
        someBusiness();

};
thread.start();

Upvotes: 1

Frettman
Frettman

Reputation: 2271

Everything executed in (a)syncExec is using the display thread and therefore blocking your UI until it returns. I suggest you use Eclipse Jobs. This will use the progress indicator that the workbench already offers out of the box.

Upvotes: 8

Related Questions