If the command takes a long time to execute, the user interface will be blocked. This happens because there is only one user interface thread, and because the command is launched from the UI, it will run in the UI thread. Instead, long-running operations should run in a background thread, and then once finished, be able to display the results. Clearly creating a new Thread
(like the clock updates initially) or other techniques such as a Timer
would work. However, the Eclipse system has a mechanism to provide a Job
to do the work instead, or UIJob
to run in the context of the UI thread.
Open the
HelloHandler
and go to theexecute
method. Replace its contents with the following:public void execute() { Job job = new Job("About to say hello") { protected IStatus run(IProgressMonitor monitor) { try { Thread.sleep(5000); } catch (InterruptedException e) { } MessageDialog.openInformation(null, "Hello", ...