Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Long running background Job needs UIThread when finished
Long running background Job needs UIThread when finished [message #141421] Fri, 24 July 2009 12:57
Eclipse UserFriend
Originally posted by: benjamin.wolff.web.de

Hi,


a short abstract about my use-case:
the user starts a document creation process in my application,
the creation may take some time, so i start a background job
and display the progessMonitor which displays the status.
after the creation is done, the created file will be offered
as a download by opening an ExternalBrowser and setting the URL
to a FileServiceHandler with the proper parameters (filename etc.).
the FileServiceHandler then sends the File via output stream to
the user so he can save it on his local storage.

the problem is, for opening the external browser (ExternalBrowser class),
i need the access to the RWT session, but when i use a background job
i don't have the access to the session and cannot open an ExternalBrowser
on finish. I could use a display.asynexec, but then the progressmonitor
is not update because the asyncexec waits until the results can be rendered,
which means that the job needs to complete first, during this time there
is no interaction possible with the UI.

for now i solved it like this:
the background job is started. after that (in the same method) i manually
run the main event loop:

// Mark the Job as a User Job and start it
job.setUser(true);
job.schedule();

while (job.getResult() == null) {
if (!Display.getCurrent().readAndDispatch()) {
Display.getCurrent().sleep();
}
}


so as long as the job is not done, interaction with the UI is still possible
and the progress monitor updates properly. after the job i also have access
to the same RWT session (uithread) and can open the ExternalBrowser.

this works good, but i don't feel very comfortable to manually read and dispatch
the events here, and maybe there is a common/better solution for this?!

basically i need to:
- start a background job, the progressmonitor should be displayed and updated
- after the job i need the possibility to (asynchronously) open an external browser/offer the download to the user

the first point is no problem and works out of the box, but the second issue is more complicated because
i need to asynchronously call the UI and open the external browser. i could not achieve the
desired behaviour with display.(a)syncExec().

i hope you can understand my use-case :)). if something is not clear please ask, i
will try to provide more information.


thx!!


greetings,
ben
Previous Topic:[SingleSourcing] Click Button programmatically - also in RCP
Next Topic:Unable to find file in classpath
Goto Forum:
  


Current Time: Thu Sep 26 08:52:54 GMT 2024

Powered by FUDForum. Page generated in 0.03675 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top