[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: ProgressBar scroll Problem when run asynchronism thread at sametime

display.asyncExec is not the solution for asynchronous threading. It just adds the request to the UI thread queue. For pure "asynchronous threading", you should run your background task in a new thread created by implementing Runnable or you can use the Jobs API. you cab then display.asyncExec to update the UI from your new thred/job.

Regards,
Anup

Chenghao Situ wrote:
Hi,

I'm trying to use ProgressBar, but I met problem when I use INDETERMINATE mode and then start a asynchronism thread, see below code:

Display display = new Display();
final Shell shell = new Shell(display);
shell.setBounds(100, 100, 400, 300);
display.asyncExec(new Runnable(){


public void run() {
try {
Thread.sleep(5000);
//simulate long time task
} catch (InterruptedException e) {
//ignore
}
}
});
final ProgressBar progressBar = new ProgressBar(shell, SWT.INDETERMINATE);
progressBar.setMaximum(100);
progressBar.setMinimum(0);
progressBar.setSelection(20);
progressBar.setBounds(10, 15, 225, 20);
shell.open();
while(!shell.isDisposed())
{
if(!display.readAndDispatch())
display.sleep();
}


The progress bar seems be blocked, and start scroll till the asynchronism thread exit.
Using asyncExec() here as it need to update some UI elements when this thread is running.
Does some one know why the progressBar do not scroll when a asynchronism thread is running?
Is there some other solution can do same things?
What I want to do is when the back thread is running, it will update some UI element, and when it finished, it will notify UI to displose the progressBar.


Thanks.