Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » [SOLVED]Accessing GUI from another thread with progressbar
[SOLVED]Accessing GUI from another thread with progressbar [message #1374155] Thu, 22 May 2014 13:54 Go to next message
mark tal is currently offline mark talFriend
Messages: 11
Registered: July 2012
Junior Member
I have a method that collects data from GUI composites, does some logic and then updates GUI again.

While this is done, i want to display a progress bar.
This is my code:

 ProgressMonitorDialog dialog = new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());  
                                                                                                                             
try {                                                                                                                       
	dialog.run(true, false, new IRunnableWithProgress() {                                                                     
		public void run(final IProgressMonitor monitor) {                                                                       
			monitor.beginTask("Progress", IProgressMonitor.UNKNOWN);                                                              
                                                                                                                             
			Job job = new Job("Job") {                                                                                         
				@Override                                                                                                           
				protected IStatus run(IProgressMonitor arg0) {                                                                      
					Display.getDefault().asyncExec(new Runnable() {                                                                   
						public void run() {                                                                                           
						                                                                                      
							for (int i = 0; i < 1000; i++) {                                                                              
								try {                                                                                                       
									doTask();                                                                                               
								                                                                                 
							}                                                                                                             
						}                                                                                                               
					});                                                                                                               
					return Status.OK_STATUS;                                                                                          
				}                                                                                                                   
                                                                                                                             
			};                                                                                                                    
			job.schedule();                                                                                                       
			try {                                                                                                                 
                                                                                                                             
				job.join();                                                                                                         
			} catch (InterruptedException e) {                                                                                    
				// TODO Auto-generated catch block                                                                                  
				e.printStackTrace();                                                                                                
			}                                                                                                                     
                                                                                                                             
			monitor.done();                                                                                                       
					}


The first issue, the code doesn't block on job.join();

How to fix?

Update:

job.getResult() = isOK()
and job is still running in background but doesn't block at job.join();

[Updated on: Fri, 23 May 2014 19:24]

Report message to a moderator

Re: Accessing GUI from another thread with progressbar [message #1377167 is a reply to message #1374155] Fri, 23 May 2014 19:14 Go to previous message
mark tal is currently offline mark talFriend
Messages: 11
Registered: July 2012
Junior Member
My bad, the issue was with
asyncExec
as it's background operation, the JOB was completed immediately.
This why join() didn't block.

But now I have different problem, i will ask about this in a new post.
Previous Topic:String length limit of GC.textExtent() under Win32
Next Topic:Progressbar is frozen with syncExec
Goto Forum:
  


Current Time: Thu Apr 25 15:45:54 GMT 2024

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

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

Back to the top